Sorting List Boxes

The ListBox control has been good enough for many years. Why fix it if it isn’t broken? Well, that’s a matter of opinion. The ListBox control isn’t exactly broken, but it hasn’t reached its full potential. Most limitations of list boxes also apply to combo boxes. Here are a few things both of them could do better:

Those are some of the new features of the XListBoxPlus control. XListBoxPlus is another delegation control. You should have delegation mastered by now, based on the XPictureGlass, XEditor, and XDropStack controls. In this case, the control delegates to an internal ListBox control. The internal list box is what the user sees on the screen, but XListBoxPlus is what the user interacts with. All properties, methods, and events are intercepted so that the list box items can be kept in the proper order.

I discussed sorting and searching in “Sorting, Shuffling, and Searching,” in Chapter 5; now it’s time to put those algorithms to work. The Test Sort program (TSORT.VBP) also appeared in Chapter 5, but at that time, I was interested in sorting arrays. Now I’m interested in the list box part of the program. Check it out in Figure 11-3 on the following page.

Figure 11-3. Sorting arrays, collections, and list boxes.