Custom Self-Expanding MultiSelect Winforms ListBox
Author:
Peter A Bromberg
Unfortunately, the Windows Forms ComboBox class doesn't support multiple selections. Only the ListBox does.The problem with the ListBox is that if you set its height to a single item, you have to use the little up/down arrows at the right to move through the list of items, and you only get to see one of the items at a time. If you set its height big enough to show all the items, well -- there goes your real estate. What I did is to create a CustomListBox control derived from ListBox, and override its OnMouseEnter and OnMouseLeave events to automatically expand the height to exactly show all the items, allowing multiple selections, automatically sending all other controls to the back so that they don't interfere with the "view". When you are finished selecting OnMouseLeave, everything is restored to its original compact, one-line height.
More Tutorials
|