ComboBox, ListBox, CheckedListBox

These controls are also used for providing users with a list of values to choose from, ComboBox allows only single selection but it is editable which gives a chance to either select from the list of values available or enter a new value, it’s a combination of 2 controls DropDownList + TextBox. CheckedListBox by default allows multi-selection. ListBox by default allows single selection only but can be changed to multi-selection by setting the SelectionMode property either to MultiSimple [Mouse Click] or MultiExtended [Ctrl + Mouse Click], default is one.

Adding values to the controls

In the properties of the control we find a property Items, select it and click on the button beside it which opens a window, enter the values we want to add, but each in a new line.

By using Items.Add method of the control we can add values, but only one at a time. control.Items.Add(object value)

By using Items.AddRange method of the control an array of values can be added at a time. control.Items.AddRange(object[] values)

4. By using DataSource property of the control a DataTable can be bound to it so that all the records of table gets bound to the control, but as it can display only a single column we need to specify the column to be displayed using the DisplayMember property.

control.DataSource = data table
 control.DisplayMember = col name