CheckedListBox (chlb)

microsoft excel docsCheckedListBox - Allows the user to select multiple items from a list of items.

This control inherits from the ListBox control and therefore has the same properties, methods and events.
You should change the CheckOnClick property to True to let the user check and uncheck elements with a single click.
The checkboxes can be in three possible states (similar to a Checkbox control).
You can only click on a checkbox to select or clear it, the indeterminate state can only be set from code.


To add objects to the list at run time, assign an array of object references with the AddRange method.
If UseTabStops is true, the CheckedListBox will recognize and expand tab characters in an item's text, creating columns. However, the tab stops are preset and cannot be changed.


The default font is Microsoft Sans Serif 8.25 which can distort the text
This should be changed to font size 8 ???



Multiple Selection

This control does not support selecting multiple items at the same time so the SelectionMode controls whether to select a single item or no items
This control lets you check multiple items but only by selecting each one individually.


Examples

microsoft excel docs

Useful Code

This will change an item so it is selected

this.CheckedListBox1.SetItemChecked(ichartcount, true); 

This will change an item so it is NOT selected

this.CheckedListBox1.SetItemChecked(ichartcount, false); 

The SelectedItems and SelectedIndices collections have been replaced by the CheckedItems and CheckedIndices collections respectively.


for (int icount = 0; icount < objCheckedListBox.CheckedItems.Count; icount++) 
{
   sreturn = sreturn & objCheckedListBox.CheckedItems(icount).ToString();
}

Properties

BackColor(Inherited from ListBox.)
BackgroundImageLayoutGets or sets the background image layout for a ListBox as defined in the ImageLayout enumeration. (Inherited from ListBox.)
BorderStyleGets or sets the type of border that is drawn around the ListBox. (Inherited from ListBox.)
CheckedIndicesCollection of checked indexes in this CheckedListBox.
CheckedItemsCollection of checked items in this CheckedListBox.
CheckOnClickLets users to check or uncheck elements by means of a single click. Gets or sets a value indicating whether the check box should be toggled when an item is selected.
ColumnWidthGets or sets the width of columns in a multicolumn ListBox. (Inherited from ListBox.)
CustomTabOffsets Gets the width of the tabs between the items in the ListBox. (Inherited from ListBox.)
Font(Inherited from ListBox.)
ForeColor(Inherited from ListBox.)
FormatInfo Gets or sets the IFormatProvider that provides custom formatting behavior. (Inherited from ListControl.)
FormatString Gets or sets the format-specifier characters that indicate how a value is to be displayed. (Inherited from ListControl.)
FormattingEnabled Gets or sets a value indicating whether formatting is applied to the DisplayMember property of the ListControl. (Inherited from ListControl.)
HorizontalExtentGets or sets the width by which the horizontal scroll bar of a ListBox can scroll. (Inherited from ListBox.)
HorizontalScrollbarGets or sets a value indicating whether a horizontal scroll bar is displayed in the control. (Inherited from ListBox.)
IntegralHeightGets or sets a value indicating whether the control should resize to avoid showing partial items. (Inherited from ListBox.)
ItemHeightOverridden. Gets the height of the item area.
ItemsGets the collection of items in this CheckedListBox.
MultiColumnGets or sets a value indicating whether the ListBox supports multiple columns. (Inherited from ListBox.)
PreferredHeight Gets the combined height of all items in the ListBox. (Inherited from ListBox.)
RightToLeftGets or sets a value indicating whether text displayed by the control is displayed from right to left. (Inherited from ListBox.)
ScrollAlwaysVisibleGets or sets a value indicating whether the vertical scroll bar is shown at all times. (Inherited from ListBox.)
SelectedIndex Gets or sets the zero-based index of the currently selected item in a ListBox. (Inherited from ListBox.)
SelectedIndices Gets a collection that contains the zero-based indexes of all currently selected items in the ListBox. (Inherited from ListBox.)
SelectedItem Gets or sets the currently selected item in the ListBox. (Inherited from ListBox.)
SelectedValue Gets or sets the value of the member property specified by the ValueMember property. (Inherited from ListControl.)
SelectionModeThis is not supported Overridden. Gets or sets a value specifying the selection mode.
SortedGets or sets a value indicating whether the items in the ListBox are sorted alphabetically. (Inherited from ListBox.)
TextGets or searches for the text of the currently selected item in the ListBox. (Inherited from ListBox.)
ThreeDCheckBoxesLets you display 3D checkboxes. Gets or sets a value indicating whether the check boxes have a System.Windows.Forms.ButtonState of Flat or Normal.
TopIndexGets or sets the index of the first visible item in the ListBox. (Inherited from ListBox.)
UseCompatibleTextRendering Gets or sets a value that determines whether to use the compatible text rendering engine (GDI+) or not (GDI).
UseCustomTabOffsets Gets or sets a value indicating whether the ListBox recognizes and expands tab characters when it draws its strings by using the CustomTabOffsets integer array. (Inherited from ListBox.)
UseTabStopsGets or sets a value indicating whether the ListBox can recognize and expand tab characters when drawing its strings. (Inherited from ListBox.)

Methods

BeginUpdate Maintains performance while items are added to the ListBox one at a time by preventing the control from drawing until the EndUpdate method is called. (Inherited from ListBox.)
ClearSelectedUnselects all items in the ListBox. (Inherited from ListBox.)
EndUpdateResumes painting the ListBox control after painting is suspended by the BeginUpdate method. (Inherited from ListBox.)
FilterItemOnProperty Overloaded. Returns the current value of the ListControl item, if the item is a property of an instance of the ListControl class. (Inherited from ListControl.)
FindStringOverloaded. Finds the first item in the ListBox that starts with the specified string. (Inherited from ListBox.)
FindStringExactOverloaded. Finds the first item in the ListBox that exactly matches the specified string. (Inherited from ListBox.)
GetItemHeight Returns the height of an item in the ListBox. (Inherited from ListBox.)
GetItemRectangle Returns the bounding rectangle for an item in the ListBox. (Inherited from ListBox.)
GetItemText Returns the text representation of the specified item. (Inherited from ListControl.)
GetScaledBounds Retrieves the bounds within which the ListBox is scaled. (Inherited from ListBox.)
IndexFromPoint Overloaded. Returns the zero-based index of the item at the specified coordinates. (Inherited from ListBox.)
IsInputKey Handles special input keys, such as PAGE UP, PAGE DOWN, HOME, END, and so on. (Inherited from ListControl.)
RefreshForces the control to invalidate its client area and immediately redraw itself and any child controls. (Inherited from ListBox.)
ResetBackColor(Inherited from ListBox.)
ResetForeColor (Inherited from ListBox.)
ToString Returns a string representation of the ListBox. (Inherited from ListBox.)

Methods - Selection

SelectedIndexGets or sets the zero-based index of the currently selected item in a single-selection ListBox.
SelectedItemGets the currently selected item in a single-selection ListBox.

Methods - Checked

GetItemCheckedDetermines if a particular zero-based item is currently checked.
GetItemCheckStateDetermines the state of the checkbox for a particular zero-based item.
CheckedIndicesRepresents the collection containing the index positions of all the checked items.
CheckedItemsRepresents the collection of checked items.
SetItemCheckedSelects or clears the checkbox for a particular zero-based item.
SetItemCheckStateChanges the state of the checkbox for a particular zero-based item.

Methods - Redundant

GetSelectedDetermines if a particular zero-based item is the item that is currently selected.
SetSelectedSelects or clears the current selected item. This is the item which is highlighted and has no relationship to whether an item is checked.

Events

BackgroundImageChanged Occurs when the BackgroundImage property of the label changes. (Inherited from ListBox.)
BackgroundImageLayoutChanged Occurs when the BackgroundImageLayout property changes. (Inherited from ListBox.)
Format Occurs when the control is bound to a data value. (Inherited from ListControl.)
FormatInfoChanged Occurs when the value of the FormatInfo property changes. (Inherited from ListControl.)
FormatStringChanged Occurs when value of the FormatString property changes (Inherited from ListControl.)
FormattingEnabledChanged Occurs when the value of the FormattingEnabled property changes. (Inherited from ListControl.)
ItemCheck Occurs when the checked state of an item changes.
MouseClick Occurs when the user clicks the CheckedListBox control with the mouse.
PaddingChanged Occurs when the value of the Padding property changes. (Inherited from ListBox.)
PaintOccurs when the ListBox control is painted. (Inherited from ListBox.)
SelectedIndexChanged Occurs when the SelectedIndex property has changed. (Inherited from ListBox.)
SelectedValueChanged Occurs when the SelectedValue property changes. (Inherited from ListControl.)
TextChanged Occurs when the Text property is changed. (Inherited from ListBox.)

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext