Sort Listbox Selected Rows

I want to sort my listbox by grouping all selected rows together, and then by values in a particular column. This seems like a pretty simple thing to do using the CompareRows event, but so far I’ve not been successful. I compare the me.Selected(row) state of the two rows and pass back a return value to order the selected rows. If both rows have the same selection state I then compare the values in the sort column and return that as the ordering result.

Are there any known issues with trying this? Are the row selections kept in sync with the sorted rows even during the sort process? Or are the selections reapplied after the rows are sorted?

This seems like it should be pretty straightforward… any ideas???

Thanks, Joe

I’ve not tried doing that… But if the problem is that during sorting the selected function is wonky, maybe before let the sort start store a boolean into the row tags (or some celltag) for all the selected rows and use that instead of listbox.Selected.

  • Karen

Hi Karen

Thanks for the quick suggestion. I’m still trying to get my head around what’s going wrong and your suggestion is perfect for keeping the selected state in sync with the sorted rows. I’m also wondering if I should just do all the sorting outside the listbox and then just reload it. I currently have only about 300 rows so it might be fast enough.

I thought I could add this feature request to an existing app pretty quickly, so I would rather not do any more major surgery to the app than necessary.

A note for folks with this issue in the future:

Upon further study it does look like Listbox.Selected() returns “unhelpful” info during a Sort. If I gather all the row selection states using Listbox.Selected() each time CompareRows is called, the order does not change at all during the entire sort. But when the sort if finished the sorted rows carry their correct Selection state with them to their new locations.

So as Karen so aptly said; The Listbox.Selected() function is Wonky in the CompareRows event… :slight_smile:

I’ll either use Karen’s suggestion to carry the row’s selected state in a row tag or may use an all together different UI to accomplish what I need.