Page 65 - Open Soource Technologies 304.indd
P. 65
Unit 3: Understanding Controls and Control Events
Figure 3.17: ComboBox.
3.4.7.1 Notable Properties of the ComboBox
The DropDownStyle property in the Appearance section of the properties window allows us to
set the look of the ComboBox. The default value is set to DropDown which means that the
ComboBox displays the Text set by it’s Text property in the Textbox and displays it’s items in
the DropDownListBox below. Setting it to simple makes the ComboBox to be displayed with a
TextBox and the list box which doesn’t drop down. Setting it to DropDownList makes the
ComboBox to make selection only from the drop down list and restricts you from entering any
text in the textbox.
We can sort the ComboBox with it’s Sorted property which is set to False by Default.
We can add items to the ComboBox with it’s Items property.
3.4.7.2 ComboBox Event
The default event of ComboBox is SelectedIndexChanged which looks like this in code:
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As
System.Object,_
ByVal e As System.EventArgs) Handles
ComboBox1.SelectedIndexChanged
End Sub
3.4.7.3 Working with ComboBoxes
Drag a ComboBox and a TextBox control onto the form. To display the selection made in the
ComboBox in the Textbox the code looks like this:
LOVELY PROFESSIONAL UNIVERSITY 59