Combo Box Problem

Hi Everyone,

I am having a problem with a combobox in my application.

Actually I am trying to load the Groups from my groups table of my database to the combobox in order to give a selection combo for the parentgroup field in my database table.

My database table is like this:

Column Name | Type

GroupID | Int

GroupName| Varchar

ParentGroupID | Int

Now the problem is that I am able to add the names of the groups to the combobox using addItem method. But when I want to execute the insert query for inserting a new group in the database I am not able to get the GroupID of the selected group in combobox since my query is like this:

INSERT INTO Groups (GroupName, ParentGroupID) VALUES (value from GroupName textbox, GroupID of selected Group from ParentGroup Combobox)

Can someone help me to solve this problem. I tried but finally stuck when I found that combobox has no DataField and DisplayField as Combobox in VB, VB.NET or HTML have.

Please Help if someone knows the solution

Thanks in advance.

Regards

Devdatta

[1110 byte] By [kdevdattaa] at [2007-10-3 3:23:10]
# 1

Hope this will help you to get the selected item value in your combo

JComboBox combo1=new JComboBox();

String comboaction="comboBoxChanged";

combo1.setActionCommand(comboaction);

combo1.addActionListener(this);

public void actionPerformed(ActionEvent e){

if ("comboBoxChanged".equals(e.getActionCommand())) {

if(combo1.getSelectedItem()!=null){

String combovalue=combo1.getSelectedItem().toString();

System.out.println("Selected combo value : "+ combovalue);

}

}

}

Thanks

Pathuma at 2007-7-14 21:15:40 > top of Java-index,Desktop,Developing for the Desktop...
# 2

If you search around the forum there are many handy hints - if not good solutions. :o)

As you posted awhile back I am assuming you already have the answer...if not let us know, and I'll give you my solution (as I had a similar problem when I started java a few months ago-after programming in vba for ages!)...

elijah

elijaha at 2007-7-14 21:15:40 > top of Java-index,Desktop,Developing for the Desktop...