JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Immediate Solutions: Using the ListBox Class

Windows forms list boxes are based on the Control class, of course, but not directly—instead, they're based directly on the ListControl class, which also is used by other controls, such as checked list boxes. Here's the class hierarchy for the ListBox class:

Object
   MarshalByRefObject
      Component
         Control
            ListControl
               ListBox

You can find the more notable public properties of the ListBox class in Table 7.1, the more notable methods in Table 7.2, and the more notable events in Table 7.3, including those members inherited from the ListControl class. Note that as with other Windows controls, I am not listing the notable properties, methods, and events ListBox inherits from the Control class, such as the Click event—you can see all that in Tables 5.1, 5.2, and 5.3 in Chapter 5.

Table 7.1: Noteworthy public properties of ListBox objects.

Property

Means

ColumnWidth

Gets/sets column width; use with multicolumn list boxes.

DisplayMember

Indicates which property of objects in a list box to show. If this property if empty, the object's ToString method is used.

DrawMode

Gets/sets the drawing mode for the list box.

HorizontalExtent

Gets/sets the width a list box can scroll horizontally.

HorizontalScrollbar

Gets/sets if a horizontal scroll bar is displayed in the list box.

IntegralHeight

Gets/sets if the list box should resize so it doesn't show partial items.

ItemHeight

Gets/sets an item's height in the list box.

Items

Returns a collection of the items of the list box.

MultiColumn

Gets/sets if the list box supports multiple columns.

PreferredHeight

Returns the total height of all items in the list box.

ScrollAlwaysVisible

Gets/sets if a vertical scroll bar is always shown.

SelectedIndex

Gets/sets the index of the list box's currently selected item.

SelectedIndices

Gets a collection that contains the indices of all selected items in the list box.

SelectedItem

Gets/sets the selected item in the list box.

SelectedItems

Gets a collection containing the list box's selected items.

SelectionMode

Gets/sets the mode with which items are selected.

Sorted

Gets/sets if the items in the list box are sorted. The sort is alphabetical.

Text

Gets the text of the selected item in the list box.

TopIndex

Gets/sets the index of the first item that is visible in the list box.

Table 7.2: Noteworthy public methods of ListBox objects.

Methods

Means

BeginUpdate

Turns off visual updating of the list box until the EndUpdate method is called.

ClearSelected

Unselects all the items in a list box.

EndUpdate

Resumes visual updating of the list box.

FindString

Finds the first item in the list box that begins with the indicated string.

FindStringExact

Finds the first item in the list box that matches the indicated string exactly.

GetItemHeight

Returns the height of a list box item.

GetSelected

Returns True if the indicated item is selected.

IndexFromPoint

Returns the index of the item at the given coordinates.

SetSelected

Selects or deselects the indicated item in a list box.

Table 7.3: Noteworthy public events of ListBox objects.

Event

Means

SelectedIndexChanged

Occurs when the SelectedIndex property has changed.

Previous Section Next Section




JavaScript Editor Free JavaScript Editor     JavaScript Editor