operatortobe
asked on
C #.Net Windows application Transferring ListBox items to another ListBox
Hello,
I have a listbox that stores items and I have another listbox which is empty. In the middle of these listboxes I have a button names ADD. I have created an array for the items stored in the first listbox. I would like to transfer the items stored in the 1st listbox to the 2nd listbox when the item is seleceted and the ADD button is pressed.
string[] strSubs;
strSubs = new string[]{"English", "Maths", "Soscial Sciences", "Physics",};
Thanks in advance,
Erdem
I have a listbox that stores items and I have another listbox which is empty. In the middle of these listboxes I have a button names ADD. I have created an array for the items stored in the first listbox. I would like to transfer the items stored in the 1st listbox to the 2nd listbox when the item is seleceted and the ADD button is pressed.
string[] strSubs;
strSubs = new string[]{"English", "Maths", "Soscial Sciences", "Physics",};
Thanks in advance,
Erdem
Sorry, I misread your question
add this in the onclick event handler
comboBox2.Items.Add(comboB ox1.Select edItem.ToS tring());
add this in the onclick event handler
comboBox2.Items.Add(comboB
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi there,
I just had a chance to check the adding items from listbox1 to listbox2. It works fine, however if the user doesn't choose ant item from the listbox1 and just hits the ADD button I get this following message;
"NUll Reference exception was not handled"
lstChosenSubs.Items.Remove (lstChosen Subs.Selec tedItem.To String());
I guess I need to use the try and catch to handle this exception,right? Any idea how should I use it?
Regards,
I just had a chance to check the adding items from listbox1 to listbox2. It works fine, however if the user doesn't choose ant item from the listbox1 and just hits the ADD button I get this following message;
"NUll Reference exception was not handled"
lstChosenSubs.Items.Remove
I guess I need to use the try and catch to handle this exception,right? Any idea how should I use it?
Regards,
Yes - check the value of the SelectedIndex - if -1 then there is nothing selected - simply do nothing.
foreach (object o in comboBox1.Items)
{
comboBox2.Items.Add(o.ToSt
}