Results 1 to 3 of 3
  1. #1
    ashin is offline Member
    Join Date
    Nov 2008
    Posts
    71
    Rep Power
    0

    Default removeSelectionListener in list

    hi guys, how can i use the removeselectionlistener?

    this is the scenario: i have a combo box (COMBO) and a Listbox or (LIST).... and then in combo items are (Course, Section).. so when i choose the Course, lists of course will display in the listbox then when i select the section it will display the lists of sections.. but what happened was when i select course it will display courselist but when i select the section the courselist is still there plus the section lists in the Lists... so how can clear the list everytime i select either of the two... thanks
    :cool:

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

    Default

    Quote Originally Posted by ashin View Post
    hi guys, how can i use the removeselectionlistener?

    this is the scenario: i have a combo box (COMBO) and a Listbox or (LIST).... and then in combo items are (Course, Section).. so when i choose the Course, lists of course will display in the listbox then when i select the section it will display the lists of sections.. but what happened was when i select course it will display courselist but when i select the section the courselist is still there plus the section lists in the Lists... so how can clear the list everytime i select either of the two... thanks
    Which model do you use in your list?
    The DefaultListModel has methods like removeAll() or clear(), if you use the AbstractListModel, you dont have methods like these, you could instantiate a new Listmodel and set that new model to your list. I would use the DefaultListModel or a own model, if i know that i want to change my model.

    (SWT / JFace - ooh sorry , i overlooked that ;(
    Last edited by eRaaaa; 02-13-2011 at 09:35 AM.

  3. #3
    ashin is offline Member
    Join Date
    Nov 2008
    Posts
    71
    Rep Power
    0

    Default

    hi.. thank you for your idea... i put the removeAll()... this is my code:

    cmbString.addSelectionListener(new SelectionAdapter(){
    public void widgetSelected(SelectionEvent es)
    {

    listofCourse.removeAll();

    try{

    if(cmbString.getText().equals("Course"))
    {
    Class.forName("com.microsoft.sqlserver.jdbc.SQLSer verDriver");
    String URL="jdbc:sqlserver://PAL:1433; databaseName=CLMS";
    Connection connect = DriverManager.getConnection(URL,"sa","ashinisha");

    String query ="SELECT CourseCodeID FROM tblCourse cid inner join tblSchoolyear sy on cid.sem=sy.sem WHERE sy.isactive='1'";
    Statement stmt=connect.createStatement();
    ResultSet rs = stmt.executeQuery(query);
    while(rs.next())
    {
    listofCourse.add(rs.getString("CourseCodeID"));
    //listofCourse.removeSelectionListener(widgetSelecte d(es));


    }

    }

    else if(cmbString.getText().equals("Section"))
    {
    Class.forName("com.microsoft.sqlserver.jdbc.SQLSer verDriver");
    String URL="jdbc:sqlserver://PAL:1433; databaseName=CLMS";
    Connection connect = DriverManager.getConnection(URL,"sa","ashinisha");

    String query ="SELECT idSec FROM tblSection sec inner join tblSchoolyear sy on sec.syid=sy.syid WHERE sy.isactive='1'";
    Statement stmt=connect.createStatement();
    ResultSet rs = stmt.executeQuery(query);
    while(rs.next())
    {
    listofCourse.add(rs.getString("idSec"));
    //listofCourse.removeAll();
    }
    }

    }
    catch(Exception rr)
    {System.out.println(rr.getMessage());}
    }

    });
    Last edited by ashin; 02-13-2011 at 08:53 AM.
    :cool:

Similar Threads

  1. Replies: 8
    Last Post: 11-04-2011, 09:30 PM
  2. Replies: 2
    Last Post: 11-22-2009, 06:24 PM
  3. Replies: 3
    Last Post: 11-21-2009, 06:48 PM
  4. how to create list of list in java ???
    By ilayaraja in forum Advanced Java
    Replies: 1
    Last Post: 10-26-2009, 05:30 PM
  5. How to access ArrayList in List of List?
    By alvations in forum New To Java
    Replies: 5
    Last Post: 10-08-2008, 01:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •