Multiple rows in a single column in a SQL statement
Can anyone provide me with a simple sql which will run on the below table (USERROLE table)
ID ROLEUSER ROLENAME
1 user1 GL
2 user2 OBI_AP
3 user1 OBI_AP
4 user2 GL
5 user1 OBI_AR
6 user2 AR
7 user3 GL
and give the result as
ROLEUSER ROLENAMES
user1 GL;OBI_AP;OBI_AR
user2 OBI_AP;GL;AR
user3 GL
Thanks
Vikram
In 10g,
satyaki>
satyaki>select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production
Elapsed: 00:00:01.12
satyaki>
satyaki>
satyaki>with t2
2 as
3 (
4 select 1 id, 'user1' ROLEUSER, 'GL' ROLENAME from dual
5 union all
6 select 2, 'user2', 'OBI_AP' from dual
7 union all
8 select 3, 'user1', 'OBI_AP' from dual
9 union all
10 select 4, 'user2', 'GL' from dual
11 union all
12 select 5, 'user1', 'OBI_AR' from dual
13 union all
14 select 6, 'user2', 'AR' from dual
15 union all
16 select 7, 'user3', 'GL' from dual
17 )
18 select ROLEUSER ,
19 substr( string, 2 ) as string
20 from dual
21 where 1 = 2
22 model
23 reference t_ref
24 on
25 (
26 select row_number() over ( order by id ) - 1 as row_num ,
27 count(*) over () - 1 as max_row_num ,
28 ROLEUSER ,
29 ROLENAME
30 from t2
31 where ROLENAME is not null
32 order by ROLENAME
33 )
34 dimension by( row_num )
35 measures ( max_row_num, ROLEUSER, ROLENAME )
36 main t_main
37 dimension by ( cast( null as varchar2(4000) ) as ROLEUSER )
38 measures ( cast( null as varchar2(4000) ) as string )
39 rules
40 iterate( 4294967295 )
41 until
42 (
43 t_ref.max_row_num[0] is null or
44 iteration_number >= t_ref.max_row_num[0]
45 )
46 (
47 string[ t_ref.ROLEUSER[iteration_number] ] = string[ cv() ] || ';' ||
48 t_ref.ROLENAME[ iteration_number ]
49 )
50 order by 1;
ROLEUSER STRING
user1 GL;OBI_AP;OBI_AR
user2 OBI_AP;GL;AR
user3 GL
Elapsed: 00:00:00.26
satyaki>Regards.
Satyaki De.
Similar Messages
-
How To Concatenate Column Values from Multiple Rows into a Single Column?
How do I create a SQL query that will concatenate column values from multiple rows into a single column?
Last First Code
Lesand Danny 1
Lesand Danny 2
Lesand Danny 3
Benedi Eric 7
Benedi Eric 14
Result should look like:
Last First Codes
Lesand Danny 1,2,3
Benedi Eric 7,14
Thanks,
David JohnsonStarting with Oracle 9i
select last, first, substr(max(sys_connect_by_path(code,',')),2) codes
from
(select last, first, code, row_number() over(partition by last, first order by code) rn
from a)
connect by last = prior last and first = prior first and prior rn = rn -1
start with rn = 1
group by last, first
LAST FIRST CODES
Lesand Danny 1,2,3
Benedi Eric 7,14Regards
Dmytro -
Concatenate multiple row values into single column value
Hello,
Can anyone please refresh my memory on how to concatenate multiple row values into a single column value.
In the following query, I will get multiple denial reasons per application and I would rather return all denial reasons on one line.
SELECT a.application_id, a.membership_number,
r.reason_text AS denial_reason,
a.appl_receipt_date AS application_receipt_date,
a.plan_request_1 AS application_plan_code,
a.adjudication_date AS application_denial_date
FROM application a, PLAN p, application_reason ar, reason r
WHERE a.plan_request_1 = p.plan_cd
AND a.application_id = ar.application_id
AND ar.reason_id = r.reason_id
AND a.adjudication_cd = 'D'
AND a.appl_receipt_date BETWEEN '01-jan-2006' AND '31-dec-2006'
AND p.plan_type_id = 12 and a.application_id = :appId
ORDER BY application_id
Any help is greatly appreciated.
Thanks,
-Christinefound the following
SELECT deptno,
LTRIM(MAX(SYS_CONNECT_BY_PATH(ename,','))
KEEP (DENSE_RANK LAST ORDER BY curr),',') AS employees
FROM (SELECT deptno,
ename,
ROW_NUMBER() OVER (PARTITION BY deptno ORDER BY ename) AS curr,
ROW_NUMBER() OVER (PARTITION BY deptno ORDER BY ename) -1 AS prev
FROM emp)
GROUP BY deptno
CONNECT BY prev = PRIOR curr AND deptno = PRIOR deptno
START WITH curr = 1;
DEPTNO EMPLOYEES
10 CLARK,KING,MILLER
20 ADAMS,FORD,JONES,SCOTT,SMITH
30 ALLEN,BLAKE,JAMES,MARTIN,TURNER,WARD
3 rows selected.at http://www.oracle-base.com/articles/10g/StringAggregationTechniques.php -
Create a view to shows data from multiple rows in a single column
Hi all - this is probably posted in the wrong forum but I couldn't find which was the correct one.
I am almost a complete novice at sql but I have a need to create a view which can be developed at 10g (which runs efficiently as the volumes are likely to be high) which will do the following.
Original table with columns Parent_code, Child_code
Parent_Code Child_Code
1000 2000
1000 3000
1000 4000
2000 3000
2000 5000
(note Parents can have multiple children and a child can have multiple parents!)
What I need to end up with in my view is the following
Child_Code Parent_List
2000 '1000 (3)'
3000 '1000 (3), 2000 (2)'
4000 '1000 (3)'
5000 '2000 (2)'
Note the number in parantheses is the number of children that the parent has - ie in the original table parent 1000 has 3 rows (one for each child)
This view is then to be used as a look up (on child code) for a business objects report.
Is there anyone who could PLEASE, PLEASE help me fairly quickly on this as I have very little time to find a solution?Hi,
You can test these ones :
select child_code
, ltrim(sys_connect_by_path(parent_info,', '), ', ') as parent_list
from (
select child_code
, to_char(parent_code) ||
' (' ||
count(*) over(partition by parent_code) ||
')' as parent_info
, row_number() over(partition by child_code order by parent_code) rn
from your_table
where connect_by_isleaf = 1
connect by prior rn = rn-1
and prior child_code = child_code
start with rn = 1
select child_code,
rtrim(
extract(
xmlagg(xmlelement("e",parent_info||', ') order by parent_info)
, '//text()'
) as parent_list
from (
select child_code,
to_char(parent_code) ||
' (' ||
count(*) over(partition by parent_code) ||
')' as parent_info
from your_table
group by child_code
;What you need is called "string aggregation".
See here for various techniques, including the two above : http://www.oracle-base.com/articles/misc/StringAggregationTechniques.php -
How to display the multiple rows in a single column ?
Hi,
I have the Query like this :
SELECT MS.SUBJECT, MS.MESSAGEDESC, MS.MSGDATE, MAT.ATTACHMENT
FROM MESSAGES MS, MSESAGEATTACHEMTASSO MAA, (select pga.programid,
act.accountname,
row_number() over(partition by pga.programid order by act.accountname) rn
from accounttypes act, programpursesasso pga
where act.accounttypeid = pga.accounttypeid ) MSGATTACHMENTS
WHERE MS.MESSAGEID = MAA.MESSAGEID
AND MAA.MSGATTACHMENTID = MAT.MSGATTACHMENTID
AND MS.MESSAGEID = 1;
If i have multiple messageAttachments for single message ., i want to display them in a single row.,
like :
subject messagedesc msgdate attachment1 attachment2 .....attachmentn
test test 10/10/2007 test test test
can any one help me out ., how can i do this using simple sql query ?Hi,
Thanks for the Reply .,
I have the 2 table like :
DESC MESSAGES;
Name Type Nullable Default Comments
MESSAGEID NUMBER(16)
EMAILFROM VARCHAR2(50) Y
EMAILTO VARCHAR2(50) Y
SUBJECT VARCHAR2(500) Y
MESSAGEDESC VARCHAR2(2000) Y
MSGDATE DATE Y
MSGSTATUS NUMBER(1) Y
MSGDELETESTATUS NUMBER(1) Y
SQL> DESC MESSAGES;
Name Type Nullable Default Comments
MESSAGEID NUMBER(16)
EMAILFROM VARCHAR2(50) Y
EMAILTO VARCHAR2(50) Y
SUBJECT VARCHAR2(500) Y
MESSAGEDESC VARCHAR2(2000) Y
MSGDATE DATE Y
MSGSTATUS NUMBER(1) Y
MSGDELETESTATUS NUMBER(1) Y
SQL> DESC MSGATTACHMENTS;
Name Type Nullable Default Comments
MSGATTACHMENTID NUMBER(16)
ATTACHMENT CLOB
ATTACHMENTDATE DATE Y
SQL> DESC MSESAGEATTACHEMTASSO;
Name Type Nullable Default Comments
MSGATTCHID NUMBER(16)
MESSAGEID NUMBER(16) Y
MSGATTACHMENTID NUMBER(16) Y
What I need Is :
If One Msg is having multiple attachement , then i want to display all the attachment in a single row along with MsgSubject, MsgDate, MsgDesc like
I want to dipaly the MsgSubject, MsgDesc, MsgDate, Attachment1
MsgSubject MsgDate Msgdesc Attachment1 Attachment2 Attachment3 ...etc -
SQL - Multiple rows in a single column
Hi everyone,
I have a little question,
The result of my query looks like this:
VALOR
HERRERA
ANDREW
CHARLES
But I need they look like this:
VALOR
HERRERA - ANDREW - CHARLES
How I can do that without using PL/SQL?
Thanks for the help.Hi Justin,
Thanks for reply. The answer for your questions are:
1) No, sometimes could be 1 or 2 or 3 or....n
2) The true is that the result of the query have more columns. Here is the result of the query:
ID NAME VALUE SEC
150 ALGOMAS 44 1
150 AQWER 56456 1
150 DFDSF FG345143 1
150 GFDGDF 5433 1
150 TEST_123 HERRERA 1
166 ALGOMAS 22 1
166 AQWER 33 1
166 DFDSF 44 1
166 GFDGDF 55 1
166 TEST_123 ANDREW 1
243 ALGOMAS 1 1
243 AQWER 2 1
243 DFDSF 3 1
243 GFDGDF 4 1
243 TEST_123 WINDSOR 1
505 ALGOMAS VALOR DE CARAC 1
505 AQWER VALOR DE CARAC 1
505 DFDSF DDFDF 1
505 GFDGDF DFGG 1
505 TEST_123 HERRERA 1
505 TEST_123 CHARLES 2
505 TEST_123 ANDREW 3
If you see the three last rows, it repeat the NAME and the ID, What I need is that three records combine in one only row.
This is really a subquery, only need the VALUE column for the "big query", but when i execute the big query, i got the ORA-01427 error: single-row subquery returns more than one row. I know that error comes out because the NAME = TEST_123 in the ID = 505 have more than one value, so, if there is any way to put that values in only one rows, it resolve my problems.
3) Oracle Database 10g Release 10.2.0.1.0
I offer apologies if the initial information was not enough.
Once again, thanks for reply.
LCJ. -
Concatenate multiple rows in a single column
Hi
I am using Web Intelligence v4.0x (i think) and I am hoping to get help.
My query (from Performance Management Module) has a field name called "Device Name" and it has two rows, server1 and server 2 (maximum of 33 servers)
I am trying to concatenate these values so that a blank cell in a report reads
"Devices are: server1, server2"
I am not able to concatenate server1 and server2 (i.e. get server1, server2) in the above statement. I've tried to use Previous(Self) and it does not work. I get output in two rows as
server1,
server2,
Any assistance or direction is appreciated.
Thanks - KevHi Jothi,
The solution that helped me earlier
"VAR1 =Replace(ReportFilter([Customer]);";";",")"
worked for one Customer ID that had two (or more) invoice# related to that Customer ID.
If there is more than one customer ID fetched by the query, the above solution merges all the related invoice# in that variable and does not merge invoice# per Customer ID.
E.g.
Customer ID Invoice ID
0001 P100
0001 P101
0002 P150
0002 P151
Desired Output
Customer ID Invoice ID
0001 P100, P101
0002 P150, P151
Actual Output: The query merges as:
Customer ID Invoice ID
0001 P100, P101, P150, P151
0002 P100, P101, P150, P151
and so on till the last customer ID is fetched.
Is it possible to tweak the query to obtain the Desired Output? Your help is appreciated.
Thanks - Kavan -
Concat rows values into single column
Hi All,
How can I concat values of a multiple rows into a single column by separating them by comma.
Eg:
SELECT empno FROM emp;
empno
1
2
3
4
I want output should be:
Empnos
1,2,3,4
Thanks & Regards,
DanishMichaelS wrote:
Or
SQL> select rtrim(xmlagg(xmlelement(e, empno || ',')).extract('//text()').extract('//text()') ,',') empnos from emp
EMPNOS
7369,7499,7521,7566,7654,7698,7782,7788,7839,7844,7876,7900,7902,7934
Hi Michael,
is it an error or is it correct to put extract 2 times? This is giving to me the same result:
select rtrim(xmlagg(xmlelement(e, empno || ',')).extract('//text()'),',') empnos from emp;
EMPNOS
7369,7499,7521,7566,7654,7698,7782,7788,7839,7844,7876,7900,7902,7934 Regards.
Al -
Multiple row as a single row in a column
Hi,
I want to select Multiple rows into a single line in 'Single Column Table' .
For ex:
Employee table has only one column , named as empname . it has three rows
Select empname from emp;
empname
thambi
peter
antony
My expected result: thambi,peter,antonyHow do I ask a question on the forums?
https://forums.oracle.com/forums/thread.jspa?threadID=2174552#9360002 -
How do I insert multiple rows from a single form ...
How do I insert multiple rows from a single form?
This form is organised by a table. (just as in an excel format)
I have 20 items on a form each row item has five field
+++++++++++ FORM AREA+++++++++++++++++++++++++++++++++++++++++++++++++++++
+Product| qty In | Qty Out | Balance | Date +
+------------------------------------------------------------------------+
+Item1 | textbox1 | textbox2 | textbox3 | date +
+ |value = $qty_in1|value= &qty_out1|value=$balance1|value=$date1 +
+------------------------------------------------------------------------+
+Item 2 | textbox1 | textbox2 | textbox4 | date +
+ |value = $qty_in2|value= $qty_out1|value=$balance2|value=$date2 +
+------------------------------------------------------------------------+
+ Item3 | textbox1 | textbox2 | textbox3 | date +
+------------------------------------------------------------------------+
+ contd | | | +
+------------------------------------------------------------------------+
+ item20| | | | +
+------------------------------------------------------------------------+
+ + + SUBMIT + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Database Structure
+++++++++++++++++
+ Stock_tabe +
+---------------+
+ refid +
+---------------+
+ item +
+---------------+
+ Qty In +
+---------------+
+ Qty Out +
+---------------+
+ Balance +
+---------------+
+ Date +
+++++++++++++++++
Let's say for example user have to the use the form to enter all 10 items or few like 5 on their stock form into 4 different textbox field each lines of your form, however these items go into a "Stock_table" under Single insert transaction query when submit button is pressed.
Please anyone help me out, on how to get this concept started.Hello,
I have a way to do this, but it would take some hand coding on your part. If you feel comfortable hand writing php code and doing manual database calls, specificaly database INSERT calls you should be fine.
Create a custom form using the ADDT Custom Form Wizard that has all the rows and fields you need. This may take a bit if you are adding the ability for up to 20 rows, as per your diagram of the form area. The nice thing about using ADDT to create the form is that you can setup the form validation at the same time. Leave the last step in the Custom Form Wizard blank. You can add a custom database call here, but I would leave it blank.
Next, under ADDT's Forms Server Behaviors, select Custom Trigger. At the Basic tab, you enter your custom php code that will be executed. Here you are going to want to put your code that will check if a value has been entered in the form and then do a database INSERT operation on the Stock_table with that row. The advanced tab lets you set the order of operations and the name of the Custom Trigger. By default, it is set to AFTER. This means that the Custom Trigger will get executed AFTER the form data is processed by the Custom Form Transaction.
I usually just enter TEST into the "Basic" tab of the Custom Trigger. Then set my order of operations in the "Advanced" tab and close the Custom Trigger. Then I go to the code view for that page in Dreamweaver and find the Custom Trigger function and edit the code manually. It's much easier this way because the Custom Trigger wizard does not show you formatting on the code, and you don't have to keep opening the Wizard to edit and test your code.
Your going to have to have the Custom Trigger fuction do a test on the submitted form data. If data is present, then INSERT into database. Here's a basic example of what you need to do:
In your code view, the Custom Trigger will look something like this:
function Trigger_Custom(&$tNG) {
if($tNG->getColumnValue("Item_1")) {
$item1 = $tNG->getColumnValue("Item_1");
$textbox1_1 = $tNG->getColumnValue("Textbox_1");
$textbox1_2 = $tNG->getColumnValue("Textbox_2");
$textbox1_3 = $tNG->getColumnValue("Textbox_3");
$date1 = $tNG->getColumnValue("Textbox_3");
$queryAdd = "INSERT INTO Stock_table
(item, Qty_In, Qty_Out, Balance, Date) VALUES($item1, $textbox1_1, $textbox1_2, $textbox1_3, $date1)"
$result = mysql_query($queryAdd) or die(mysql_error());
This code checks to see if the form input field named Item_1 is set. If so, then get the rest of the values for the first item and insert them into the database. You would need to do this for each row in your form. So the if you let the customer add 20 rows, you would need to check 20 times to see if the data is there or write the code so that it stops once it encounters an empty Item field. To exit a Custom Trigger, you can return NULL; and it will jump out of the function. You can also throw custom error message out of triggers, but this post is already way to long to get into that.
$tNG->getColumnValue("Item_1") is used to retrieve the value that was set by the form input field named Item_1. This field is named by the Custom Form Wizard when you create your form. You can see what all the input filed names are by looking in the code view for something like:
// Add columns
$customTransaction->addColumn("Item_1", "STRING_TYPE", "POST", "Item_1");
There will be one for each field you created with the Custom Form Wizard.
Unfortunately, I don't have an easy way to do what you need. Maybe there is a way, but since none of the experts have responded, I thought I would point you in a direction. You should read all you can about Custom Triggers in the ADDT documentation/help pdf to give you more detailed information about how Custom Triggers work.
Hope this helps.
Shane -
Is there a way in Oracle to return multiple rows as a single string?
Hi gurus,
I just got help from your guys fixing my dynamic sql problem. What I am doing in that function is to return a single string from multiple rows and I use it in the select statement. It works fine once the problem was solved. But is there any way in Oracle to do this in the select statement only? I have a table that stores incidents (incident_id is the PK) and another table that stores the people that are involved in an incident.
Incident_table
(incident_id number PK);
Incident_people_table
(incident_id number PK/FK,
person_id number PK);
Now in a report, I need to return the multiple rows of the Incident_People_table as a single string separated by a comma, for example, 'Ben, John, Mark'. I asked the SQL Server DBA about this and he told me he can do that in SQL Server by using a variable in the sql statement and SQL Server will auomatically iterate the rows and concatenate the result (I have not seen his actual work). Is there a similar way in Oracle? I have seen some examples here for some similar requests using the sys_connect_by_path, but I wonder if it is feasible in a report sql that is already rather complex. Or should I just stick to my simpler funcion?
Thanks.
BenHi,
May be, this example will help you.
SQL> CREATE TABLE Incident_Table(
2 incident_id number
3 );
Table created.
SQL> CREATE TABLE Person_Table(
2 person_id number,
3 person_name VARCHAR2(200)
4 );
Table created.
SQL> CREATE TABLE Incident_People_Table(
2 incident_id number,
3 person_id number
4 );
Table created.
SQL> SELECT * FROM Incident_Table;
INCIDENT_ID
1
2
SQL> SELECT * FROM Person_Table;
PERSON_ID PERSON_NAME
1 John
2 Mark
3 Ben
4 Sam
SQL> SELECT * FROM Incident_People_Table;
INCIDENT_ID PERSON_ID
1 1
1 2
1 3
2 1
2 2
2 4
6 rows selected.
SQL> SELECT IT.*,
2 (
3 WITH People_Order AS (
4 SELECT IPT.incident_id, person_id, PT.person_name,
5 ROW_NUMBER() OVER (PARTITION BY IPT.incident_id ORDER BY PT.person_name) AS Order_Num,
6 COUNT(*) OVER (PARTITION BY IPT.incident_id) AS incident_people_cnt
7 FROM Incident_People_Table IPT
8 JOIN Person_Table PT USING(person_id)
9 )
10 SELECT SUBSTR(SYS_CONNECT_BY_PATH(PO.person_name, ', '), 3) AS incident_people_list
11 FROM (SELECT * FROM People_Order PO WHERE PO.incident_id = IT.incident_id) PO
12 WHERE PO.incident_people_cnt = LEVEL
13 START WITH PO.Order_Num = 1
14 CONNECT BY PRIOR PO.Order_Num = PO.Order_Num - 1
15 ) AS incident_people_list
16 FROM Incident_Table IT
17 ;
INCIDENT_ID INCIDENT_PEOPLE_LIST
1 Ben, John, Mark
2 John, Mark, SamRegards,
Dima -
Multiple rows in a single row.
I want to know how can I store the values of multiple rowe in a single row.for an example..
machine name manchine no frequency month
Lathe MOO1 yearly jan
Lathe MOO1 halfyearly feb
Lathe MOO1 weekly march and so on
I want this in a single row..
like jan feb march
Lathe M001 yearly halfyearly weekly.
and in a single row I want this as per the month specified .
In my report I have 12 months distribution for each machine.Taruna,
Just make sure understand the scenario correctly. Would you like to store the row in DB like this:
Lathe MOO1 yearly jan,feb,mar
then you expect to show in the report like this:
Lathe MOO1 yearly jan
Lathe MOO1 yearly feb
Lathe MOO1 yearly mar
Yes, you can do it this way, but somehow break the 1st principle of DB schema design - Atomic
Of course, you need to convert jan,feb,mar into list and display for each row.
string monthStr = "jan,feb,mar";
string [] months = monthStr.Split(",");
Kind Regards
-Yatsea -
Can I get multiple sums in a single column based on a "code" I place.
After importing a file of check/debit card activity from my bank, can I 'code' the line items based on tax categories ie Utilities, Medical expenses, Auto expenses, etc. and then get sums for each based on that code I placed in a single column? That would mean multiple sums in a single column based on the code used for each tax related expense. For instance, I would put UT in the column for utilities expenses and MED in the same column if it were a medical expense. I would then want the sum for all items in that column for each item code. Is this possible or do I need to use a different approach to get this information.
My guess is that the SUMIF function may be your friend.
It's well described in the *iWork Formulas and Functions User Guid*e which every user may download from the Help menu.
Yvan KOENIG (VALLAURIS, France) samedi 2 janvier 2010 21:56:39 -
Inserting multiple rows using a single Insert statement without using dual
Hi all,
i am trying to insert multiple rows using a single insert statement like the below one.
The below one works fine..
But is there any other change that can be done in the below one without using dual...
insert all
into ps_hd_samp (num1,num2) values (1,1)
into ps_hd_samp (num1,num2) values (2,2)
into ps_hd_samp (num1,num2) values (3,3)
select 1 from dual;NiranjanSe wrote:
Hi all,
i am trying to insert multiple rows using a single insert statement like the below one.
The below one works fine..
But is there any other change that can be done in the below one without using dual...
insert all
into ps_hd_samp (num1,num2) values (1,1)
into ps_hd_samp (num1,num2) values (2,2)
into ps_hd_samp (num1,num2) values (3,3)
select 1 from dual;
SQL> create table ps_hd_samp (num1 number,num2 number);
Table created.
SQL> insert all
2 into ps_hd_samp (num1,num2) values (1,1)
3 into ps_hd_samp (num1,num2) values (2,2)
4 into ps_hd_samp (num1,num2) values (3,3)
5 select count(*)
6 from ps_hd_samp;
3 rows created.
SQL> select * from ps_hd_samp;
NUM1 NUM2
1 1
2 2
3 3 -
Select or deselect multiple rows with one single selection event
Does anyone know how to create a JTable which can select or deselect multiple rows with one single selection event in JTable. Fore example, if the table has
row1
row2
row3
row4
row5
row6
What I need is when user select row1 or row2, both row1 and row2 should be set to be selected. Then if user press CTRL and click one of row3 or row4, both of them should be selected including the previouse selected row1 and row2.
For deselection, if row1 and row2 are selected, when users deselect one of row1 or row2, both of them should be deselected.
Hopefully someone can give me a hint.Here is a partial solution using a JList. Only one line gets highlighted when the user makes a selection in the list. But, two lines are returned. There is a blank line between every two lines.
private void addLineToList() {
String a = f_one.getText();
String b = f_two.getText();
if (a.length() == 0) {
Utils.showInformationMessage("Item field is empty.");
f_one.requestFocusInWindow();
return;
if (b.length() == 0) {
Utils.showInformationMessage("Match field is empty.");
f_two.requestFocusInWindow();
return;
model.addElement("item: " + a);
model.addElement("match: " + b);
model.addElement(" ");
int size = model.getSize();
pairList.setSelectedIndex(size - 3);
f_one.setText("");
f_two.setText("");
f_one.requestFocusInWindow();
private void editList() {
if (pairList.getSelectedValue().toString().equalsIgnoreCase(" ")) {
Toolkit.getDefaultToolkit().beep();
f_one.requestFocusInWindow();
return;
if (!f_one.getText().equals("")) {
int result = JOptionPane.showConfirmDialog(this,
"The Item field contains text. Replace the text?",
"Flash Card Activity", JOptionPane.YES_NO_OPTION,
OptionPane.INFORMATION_MESSAGE);
if (result == JOptionPane.NO_OPTION) return;
if (!f_two.getText().equals("")) {
int result = JOptionPane.showConfirmDialog(this,
"The Match field contains text. Replace the text?",
"Flash Card Activity", JOptionPane.YES_NO_OPTION,
JOptionPane.INFORMATION_MESSAGE);
if (result == JOptionPane.NO_OPTION) return;
String item = "";
String match = "";
int index = pairList.getSelectedIndex();
String choice = model.getElementAt(index).toString();
if (choice.startsWith("item")) {
item = choice;
match = model.getElementAt(index + 1).toString();
model.remove(index);
model.remove(index);
model.remove(index);
else {
item = model.getElementAt(index - 1).toString();
match = choice;
model.remove(index + 1);
model.remove(index);
model.remove(index - 1);
int size = model.getSize();
if (size > 2) {
pairList.setSelectedIndex(size - 2);
f_one.setText(item.substring(6));
f_two.setText(match.substring(7));
f_one.requestFocusInWindow();
}
Maybe you are looking for
-
I have a Live cam voice but im sad because it is vorking verry slowly.....i have update the driver but still vorking slow.....can someone help me...
-
Is there a way to create dynamic playlists on the fly in music on smart media?
Often I'm at a friends house and we're looking through music trying to pick the next song to play as one is finishing. It would be really great to have an dynamic playlist where you could add and subtract songs as you go and so keep the music playing
-
How do I create a rule in mail that only applies to flagged messages?
I would like to create a rule in mail that would delete messages of a certain age, but I need to keep some messages safe. I would like to be able to flag these or put them in a mailbox and have a rule making messages with those flags or mailboxes saf
-
Exchange rate according to document date
Hello all, We are creating PO and then Goods receipt. I need to change exchange rate according to document date while creating Goods Reiceipt. We have done few customizing changes for this. Translation date has been updated with the document date but
-
Wallpaper zooming in and out when going to home screen
Whenever I go to my home screen, my wallpapers zooms in and out by itself and it's rather annoying. I want to know if there's a way to stop it form doing it. Is it like an effect or something? How can I turn that off? Thanks