70-526 MCTSListBoxThe ListBox control is used to provide a list of items from which the user may select one or more items. If a list box contains more items than can be displayed at one time, a vertical scroll bar is automatically added. Inheritance hierarchySystem.Object
System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.Control
System.Windows.Forms.ListControl
System.Windows.Forms.ListBox
Useful properties
Useful methodsDisplaying ItemsWhen strings are added to the Items collection, a scroll bar is automatically added to the right hand side of the control. ![]() The size and position of the bar within the scroll bar gives a good indication of how big the list is. Multi-column ListBoxOften when a list becomes too long, it is beneficial to show multiple columns. This is achieved by setting the MultiColumn property to true. listBox1.MultiColumn = true; ![]() The width of the columns can be changed by setting the ColumnWidth property to a width in pixels. listBox1.ColumnWidth = 60; ![]() Selecting Items manuallyAn item can be selected through code, by using the SelectedItem property. listBox1.SelectedItem = "Nickelback"; More than one item can be selected by setting the SelectedItem property multiple times. listBox1.SelectedItem = "Nickelback"; listBox1.SelectedItem = "Bee Gees"; This only applies if the SelectionMode property is set to either MultiExtended or MultiSimple. Items can also be selected through the SelectedIndex property in the same manner. Note: MSDN references
|