Combo box Demo in Visual Basic .Net

Download
Download is available until [expire_date]
  • Version
  • Download 73
  • File Size 110.17 KB
  • File Count 1
  • Create Date April 6, 2016
  • Last Updated April 6, 2016

Combo box Demo in Visual Basic .Net

Combo box Demo in Visual Basic .Net
A combo box is a commonly used graphical user interface widget (or control). Traditionally, it is a combination of a drop-down list or list box and a single-line editable textbox, allowing the user to either type a value directly or select a value from the list. (From Wikipedia).

In this sample program, the user will be able to add an item to the combo box control, the user can now select an item from the combo box and that selected item will be displayed in a message box.

Source code:

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text = "" Then
            MessageBox.Show("Please enter a text")
            TextBox1.Focus()
        Else
            ComboBox1.Items.Add(TextBox1.Text)
            TextBox1.Text = ""
            MessageBox.Show("item added")
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If TextBox2.Text = "" Then
            MessageBox.Show("Please enter firstname")
            TextBox2.Focus()
        ElseIf TextBox3.Text = "" Then
            MessageBox.Show("Please enter lastname")
            TextBox3.Focus()
        Else
            ComboBox2.Items.Add(TextBox2.Text & " " & TextBox3.Text)
            TextBox2.Text = ""
            TextBox3.Text = ""
            MessageBox.Show("item added")
        End If
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        MessageBox.Show("Selected item: " & ComboBox1.SelectedItem.ToString)
    End Sub

    Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
        MessageBox.Show("Selected item: " & ComboBox2.SelectedItem.ToString)
    End Sub
End Class
, , ,

Post navigation

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.