Reputation: 20012
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 http://www.deviantart.com/download/152153617/A_piece_from_my_softs____by_junaid_saeed.png
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.
Upvotes: 0
Views: 793
Reputation: 120937
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.
Upvotes: 1
Reputation: 17471
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.
Upvotes: 0