Uploaded by ohs21966

COMBO BOX & BUTTON CONTROL

advertisement
Creating a program
using Combo Box, List
box and Button
Control
The Combo Box control is used to
display a drop-down list of various
items. It is a combination of a text box
in which the user enters an item and a
drop-down list from which the user
selects an item.
Note that the combo box shows one
item at a time.
Properties of Combo Box Control
Items
Gets an object representing the collection of
the items contained in this Combo Box.
SelectedIndex
Gets or sets the index specifying the
currently selected item.
SelectedItem
Gets or sets currently selected item in the
Combo Box.
Sorted
Gets or sets a value indicating whether the
items in the combo box are sorted.
Events in Combo Box
DropDown
Occurs when the drop-down portion of a
combo box is displayed.
SelectedIndexChanged
Occurs when the SelectedIndex property
of a ComboBox control has changed.
To add items to the combo box at design time from the
Properties window. Here are the steps:
Step 1) Open the design tab and click the combo box
control.
Step 2) Move to the Properties window and view the Items
option.
Step 3) Click the Items in Properties tab located to the right
of (Collection).
Step 4)You will see a new window. This is where you
should add items to the combo box, as shown below:
Step 5) Once done with typing the items, click the
OK button.
Step 6) Click the Start button from the top
toolbar and click the dropdown icon on the
combo box.
The program interface
The program code for Add item
Public Class Form1
Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
If ComboBox1.SelectedIndex > -1 Then
Dim index1 As Integer
index1 = ComboBox1.SelectedIndex
Dim item1 As Object
item1 = ComboBox1.SelectedItem
ListBox1.Items.Add(item1)
End If
End Sub
End Class
The program code for Remove item
Public Class Form1
Private Sub Button2_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles
Button2.Click
ListBox1.Items.RemoveAt(ListBox1.Sel
ectedItem)
End Sub
End Class
The program code for Sort
Public Class Form1
Private Sub Button3_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles
Button3.Click
ListBox1.Sorted = True
End Sub
End Class
The program code clear
Public Class Form1
Private Sub Button4_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles
Button4.Click
ListBox1.Items.Clear()
End Sub
End Class
The program code for Exit
Public Class Form1
Private Sub
Button5_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
Button5.Click
End
End Sub
End Class
The program code
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
If ComboBox1.SelectedIndex > -1 Then
Dim index1 As Integer
index1 = ComboBox1.SelectedIndex
Dim item1 As Object
item1 = ComboBox1.SelectedItem
ListBox1.Items.Add(item1)
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button2.Click
ListBox1.Items.RemoveAt(ListBox1.SelectedItem)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button3.Click
ListBox1.Sorted = True
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button4.Click
ListBox1.Items.Clear()
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button5.Click
End
End Sub
End Class
Download