views:

218

answers:

2

I have these ListBox es.. all of them are DataBind ed to same table and they are in a table type of manner, every row corresponds to its actual value in the datbase. When i switch selection(SelectedIndexChange) on any of these ListBoxes i change the SelectedIndex of all the other ListBox es.

alt text

Now i cannot simply select "Sort = true" for any of the ListBox because doing so the values in ListBox es will not correspond to their actual values in other ListBox es. I want to provide an option to sort Acoording to one of the ListBox while keeping the correspondences valid. HOW TO DO IT .Any Suggestions.

I don't want to run any Sorting Algorithm on ListBox, picking every entry(Item) and sorting it and then changing the rest of ListBox es accordingly.

A: 

If you're needing to do exactly what you have listed, I'd recommend adding in a 'layer' of logic before actually binding to the listboxes.

i.e.:

Instead of databinding directly to the ListBoxes, create a List<> of the datarows (or your own custom object). When you need to sort the list, call the .Sort() method on the List<> for whatever property/column you need, and then clear out the ListBoxes, repopulate them based upon your List<> (probably adding the ListItems one at a time for each box), and then correct the SelectedIndex(es) of the ListBoxes.

By doing it this way, you never lose association between rows of the ListBoxes.

John
thats exactly what i am avoiding...
Junaid Saeed
+1  A: 

You should really use a ListView instead of using all those list boxes. It would make your life a lot less complicated, as it supports the functionality you are requesting without you having to worry about keeping things in sync.

klausbyskov
Yah that wud have been easy but ListBox happens to "Documented Specification" for this. I might leave Sorting but i cannot leeave ListBox :)
Junaid Saeed
And you are not in a position to question the specification, even though it makes little to no sense?
klausbyskov