List-based Controls
Slide 2 Introduction There are several controls that work with lists ComboBox ListBox CheckedListBox
Slide 3 The ComboBox Control (1) It contains a list of items Items can be populated at run-time or at design-time The SelectedIndexChanged event fires when the user selects an item The SelectedIndex property contains the 0-based index of the selected item The SelectedItem property contains the text that the user sees
Slide 4 The ComboBox Control (2) The DropDownStyle property controls how the list drops-down, and whether the box is editable Count contains the number of items in the list Adding and removing items works the same way as any collection Add, Insert, Clear, Remove
Slide 5 The ComboBox Control Adding items at design-time Set the Items property using the String Collection Editor
Slide 6 The ComboBox Control Adding items at run-time Call the Add method of the Items collection Example for (int x = 2010; x < 2016; x++) { cboSelectYear.Items.Add(x.ToString()); }
Slide 7 The ListBox Control (1) It’s really a ComboBox that does not drop- down Most of the properties work the same way Set the SelectionMode property to select one or many items One, MultiSimple, MultiExtended Call GetSelected and SetSelected to determine whether an item is selected or to select an item
Slide 8 The CheckedListBox Control It’s really just a ListBox control