Shri Shivaji Science College, Amravati
Department of Computer Science
Topic-VB.NET
Prepared By
Dr. Ujwala S. Junghare
Assistant Professor
Dept. of Computer Science
Combo box and List box
List Boxes:
•Listboxesdisplayalistofitemsfromwhichtheusercanselectoneormore.Ifthereare
toomanyitemstodisplayatonce,ascrollbarautomaticallyappearstolettheuserscroll
throughthelist.InVisualBasic.NET,eachiteminalistboxisitselfanobject.
•Itallowstheprogrammertoadditemsatdesigntimebyusingthepropertieswindowor
attheruntime.
•YoucancreatealistboxbydraggingaListBoxcontrolfromtheToolboxanddroppingit
ontheform.
You can populate the list box items either from the properties window or at runtime.
Properties of the ListBox Control:
Sr.No
.
Property & Description
1 AllowSelection
GetsavalueindicatingwhethertheListBoxcurrentlyenablesselectionoflistitems.
2 BorderStyle
Getsorsetsthetypeofborderdrawnaroundthelistbox.
3 ColumnWidth
Getsofsetsthewidthofcolumnsinamulticolumnlistbox.
4 HorizontalExtent
Getsorsetsthehorizontalscrollingareaofalistbox.
5 HorizontalScrollBar
Getsorsetsthevalueindicatingwhetherahorizontalscrollbarisdisplayedinthelistbox.
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs)
Handles MyBase.Load
' Set the caption bar text of the form.
Me.Text = "tutorialspont.com"
ListBox1.Items.Add("Canada")
ListBox1.Items.Add("USA")
ListBox1.Items.Add("UK")
ListBox1.Items.Add("Japan")
ListBox1.Items.Add("Russia")
ListBox1.Items.Add("China")
ListBox1.Items.Add("India")
End Sub
Private Sub Button1_Click(sender As Object, e As
EventArgs) Handles Button1.Click MsgBox("You have selected
" + ListBox1.SelectedItem.ToString()) End Sub
Private Sub ListBox1_SelectedIndexChanged(sender As
Object, e As EventArgs) Handles
ListBox1.SelectedIndexChanged
Label2.Text = ListBox1.SelectedItem.ToString()
End Sub
End Class
Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As
System.EventArgs) Handles Button1.Click
ListBox1.BeginUpdate()
Dim intLoopIndex As Integer
For intLoopIndex = 1 To 20
ListBox1.Items.Add("Item " &intLoopIndex.ToString())
Next intLoopIndex
ListBox1.EndUpdate()
End Sub
Combo box
The ComboBox 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.
Let's create a combo box by dragging a ComboBox control from the Toolbox and
dropping it on the form.
Sr.No. Property & Description
1 AllowSelection
Getsavalueindicatingwhetherthelistenablesselectionoflistitems.
2 AutoCompleteCustomSource
GetsorsetsacustomSystem.Collections.Specialized.StringCollectionto
usewhentheAutoCompleteSourcepropertyissettoCustomSource.
3 AutoCompleteMode
Getsorsetsanoptionthatcontrolshowautomaticcompletionworksfor
theComboBox.
4 AutoCompleteSource
Getsorsetsavaluespecifyingthesourceofcompletestringsusedfor
automaticcompletion.
5 DataBindings
Getsthedatabindingsforthecontrol.