Thanks for showing me a cleaner way to bind the data between listboxes.
I probably wasn't very clear but what I need to do is select the value in one of the list boxes (say lbOne) from within the for loop (Not by clicking on an item in the listbox on Windows form). Each item in lbOne should be selected in turn as the for loop iterates through lbOne's list.
Is there a way to select an item in lbOne inside this for loop so that the other two listboxes will select appropriate items based on data binding??
double x = 0;
foreach (object obj in lbOne.Items)
{
x = Convert.ToDouble(obj);
//select appropriate items in lbTwo and lbThree based on databinding with lbOne?????
}
Thanks!
Main Topics
Browse All Topics





by: Nash2334Posted on 2008-05-28 at 10:39:31ID: 21662500
You don't need to jump through so many hoops to populate your listboxes - the ListBox has a DisplayMember and a ValueMember property that you can specify. You can set the three listboxes to have the same datasource and different DisplayMembers. If the Selection Mode of the ListBoxes is set to "One", everything else will get taken care of for you by virtue of databinding.
In the following example, three listboxes are bound to the same datatable. Selecting an item in any of three automatically selects its partner values by virtue of databinding.
Select allOpen in new window