Click here to Skip to main content
15,918,243 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
C#
foreach (string item in listBoxAvailableStops.Items)
             {
                 if (listBoxSelectedStops.Items.Contains(item) == false)
                 {
                     listBoxSelectedStops.Items.Add(item);
                 }
                 else
                 {
                     MessageBox.Show("These Stops are already selected!");
                 }
             }


This is my code and I want to move the contents from listBoxAvailableStops to listBoxSelectedStops, but both of these listboxes are bound. So it will show an error indicating that the binding would have to be removed first. So how can we move the content from one listbox to another when both these listboxes are bound.

Thanks & Regards

Sairam Bhat
09483265647
Posted
Updated 28-Feb-11 1:26am
v4

1 solution

Hi,

Instead of adding to the list box directly, add to the underlying data source. The purpose of list box is to display the bound data, then adding to it means adding to the underlying data source. So why don't do it directly on the data source and the second list box will display it
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900