How to Make Chained Combo Box in Visual Studio - Gudio Tutorial

    Social Items


How to Make Chained Combo Box in Visual Studio

Make Chained Combo Box - Combo Box is a graphical user interface (GUI) widget, that is commonly used on desktop, website and mobile applications. This Combo Box is a combination of a drop-down list or list box and a single-line editable text box that allow users to type values ​​directly or select values ​​from the combo box list.


Design


What needs to be prepared is of course visual studio net, if in this tutorial I use visual studio which is version 2015, if you use the one below it is fine, the only difference is the net framework version and some components in it.
Okay, we are directly on the topic of the discussion.

Make Chained Combo Box

1. Open your Visual Studio.
2. If so, add 2 text box by clicking and then dragging to where you want it to be, add 2 combo box and 3 buttons.

Explanation of the controls that we added above:
Object Name Number of Object Function
Text Box 2 Textbox functions to record user names along with the user's zip code.
Combo Box 2 The combobox functions as a chain combobox where the first combobox contains a list of provinces and the second combobox contains a list of cities in the first province
Button 3 as "exit button", "reset button", "show button".
When it's finished, the results are as below:

How to Make Chained Combo Box in Visual Studio

Coding




Coding


Our application design is complete, now we go to coding:
1. Double-click on the form, it will automatically be directed to coding form_load event., Type the code like this:

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        With ComboBox1
            .Items.Add("Aceh")
            .Items.Add("Bali")
            .Items.Add("Kalimantan Timur")
            .Items.Add("Daerah Istimewa Yogyakarta")
        End With

        ComboBox2.Enabled = False
        ComboBox3.Enabled = False
    End Sub


2. Then, double-click on Combobox 1, and type the code below:

Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
        If ComboBox1.Text = "Aceh" Then
            ComboBox2.Enabled = True
            With ComboBox2
                .Items.Clear()
                .Items.Add("Banda Aceh")
                .Items.Add("Kota Sabang")
                .Items.Add("Kota Subulussalam")
                .Items.Add("Kabupaten Bireuen")
                .Items.Add("Kabupaten Gayo Lues")
                .Items.Add("Kabupaten Pidie Jaya")
                .Items.Add("Kabupaten Simeulue")
                .Items.Add("Kabupaten Aceh Tamiang")
                .SelectedIndex = 0
            End With
        ElseIf ComboBox1.Text = "Bali" Then
            With ComboBox2
                .Items.Clear()
                .Items.Add("Denpasar")
                .Items.Add("Badung")
                .Items.Add("Singaraja")
                .Items.Add("Karangasem")
                .Items.Add("Jembrana")
                .Items.Add("Bangli")
                .Items.Add("Klungkung")
                .Items.Add("Karangasem")
                .Items.Add("Gianyar")
                .SelectedIndex = 0
            End With
        ElseIf ComboBox1.Text = "Kalimantan Timur" Then
            With ComboBox2
                .Items.Clear()
                .Items.Add("Kabupaten Berau")
                .Items.Add("Kabupaten Kutai Barat")
                .Items.Add("Kabupaten Kutai Kartanegara")
                .Items.Add("Kabupaten Kutai Timur")
                .Items.Add("Kabupaten Paser")
                .Items.Add("Kota Balikpapan")
                .Items.Add("Kota Bontang")
                .Items.Add("Kota Samarinda")
                .SelectedIndex = 0
            End With
        ElseIf ComboBox1.Text = "Daerah Istimewa Yogyakarta" Then
            With ComboBox2
                .Items.Clear()
                .Items.Add("Kabupaten Bantul")
                .Items.Add("Kabupaten Gunung Kidul")
                .Items.Add("Kabupaten Kulon Progo")
                .Items.Add("Kabupaten Sleman")
                .Items.Add("Kota Yogyakarta")
                .SelectedIndex = 0
            End With
        End If
    End Sub


3. If it is finished, double-click on button 3 (three) and type the code below. On button 3 (three), it contains validation where if the user clears one of the entries a notification message will appear:

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If TextBox1.Text = "" Then
            MsgBox("Please fill in your name first", vbInformation, "Gudio")
            TextBox1.Focus()
        ElseIf ComboBox1.Text = "" Then
            MsgBox("Your province must be filled", vbInformation, "Gudio")
            ComboBox1.Focus()
        ElseIf ComboBox2.Text = "" Then
            MsgBox("Your City Name must be filled in", vbInformation, "Gudio")
            ComboBox2.Focus()
        ElseIf TextBox2.Text = "" Then
            MsgBox("Your Zip Code is still empty", vbInformation, "Gudio")
            TextBox2.Focus()
        Else
            MsgBox("Here's Your Personal Data: " & vbCrLf & _
                    vbCrLf & _
                    "Your name : " & TextBox1.Text & vbCrLf & _
                    vbCrLf & _
                    "Your province: " & ComboBox1.Text & vbCrLf & _
                    vbCrLf & _
                    "Your city: " & ComboBox2.Text & vbCrLf & _
                    vbCrLf & _
                    "Your Zip Code: " & TextBox2.Text, vbInformation, "Gudio")
        End If
End Sub


4. Double-click on button 2, then type the following code:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        ComboBox1.SelectedIndex = -1
        ComboBox2.Items.Clear()
        TextBox1.Clear()
        TextBox2.Clear()
        TextBox1.Focus()
End Sub

This code is used to reset all fields.
Get used to using your fingers to type all the codes. Don't just copy and paste the code provided. The more often you type in the program code, the more you will understand about the code.
Try running the application that you created, the result is like this, if you correctly write all the code:

How to Make Chained Combo Box in Visual Studio

Okay, it's done, the simple chain combobox tutorial we made. Sorry, if the application in this tutorial is not good because I only give a simple example tutorial. For another time, I will share a tutorial on how to make chain combobox using a database.

If anyone wants to download, the full source code is here.


That's How to Make a Chain Combo Box Using Visual Studio, I hope you all, get the benefit of this tutorial. We meet again, at other times and with other interesting tutorials.

How to Make Chained Combo Box in Visual Studio


How to Make Chained Combo Box in Visual Studio

Make Chained Combo Box - Combo Box is a graphical user interface (GUI) widget, that is commonly used on desktop, website and mobile applications. This Combo Box is a combination of a drop-down list or list box and a single-line editable text box that allow users to type values ​​directly or select values ​​from the combo box list.


Design


What needs to be prepared is of course visual studio net, if in this tutorial I use visual studio which is version 2015, if you use the one below it is fine, the only difference is the net framework version and some components in it.
Okay, we are directly on the topic of the discussion.

Make Chained Combo Box

1. Open your Visual Studio.
2. If so, add 2 text box by clicking and then dragging to where you want it to be, add 2 combo box and 3 buttons.

Explanation of the controls that we added above:
Object Name Number of Object Function
Text Box 2 Textbox functions to record user names along with the user's zip code.
Combo Box 2 The combobox functions as a chain combobox where the first combobox contains a list of provinces and the second combobox contains a list of cities in the first province
Button 3 as "exit button", "reset button", "show button".
When it's finished, the results are as below:

How to Make Chained Combo Box in Visual Studio

Coding




Coding


Our application design is complete, now we go to coding:
1. Double-click on the form, it will automatically be directed to coding form_load event., Type the code like this:

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        With ComboBox1
            .Items.Add("Aceh")
            .Items.Add("Bali")
            .Items.Add("Kalimantan Timur")
            .Items.Add("Daerah Istimewa Yogyakarta")
        End With

        ComboBox2.Enabled = False
        ComboBox3.Enabled = False
    End Sub


2. Then, double-click on Combobox 1, and type the code below:

Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
        If ComboBox1.Text = "Aceh" Then
            ComboBox2.Enabled = True
            With ComboBox2
                .Items.Clear()
                .Items.Add("Banda Aceh")
                .Items.Add("Kota Sabang")
                .Items.Add("Kota Subulussalam")
                .Items.Add("Kabupaten Bireuen")
                .Items.Add("Kabupaten Gayo Lues")
                .Items.Add("Kabupaten Pidie Jaya")
                .Items.Add("Kabupaten Simeulue")
                .Items.Add("Kabupaten Aceh Tamiang")
                .SelectedIndex = 0
            End With
        ElseIf ComboBox1.Text = "Bali" Then
            With ComboBox2
                .Items.Clear()
                .Items.Add("Denpasar")
                .Items.Add("Badung")
                .Items.Add("Singaraja")
                .Items.Add("Karangasem")
                .Items.Add("Jembrana")
                .Items.Add("Bangli")
                .Items.Add("Klungkung")
                .Items.Add("Karangasem")
                .Items.Add("Gianyar")
                .SelectedIndex = 0
            End With
        ElseIf ComboBox1.Text = "Kalimantan Timur" Then
            With ComboBox2
                .Items.Clear()
                .Items.Add("Kabupaten Berau")
                .Items.Add("Kabupaten Kutai Barat")
                .Items.Add("Kabupaten Kutai Kartanegara")
                .Items.Add("Kabupaten Kutai Timur")
                .Items.Add("Kabupaten Paser")
                .Items.Add("Kota Balikpapan")
                .Items.Add("Kota Bontang")
                .Items.Add("Kota Samarinda")
                .SelectedIndex = 0
            End With
        ElseIf ComboBox1.Text = "Daerah Istimewa Yogyakarta" Then
            With ComboBox2
                .Items.Clear()
                .Items.Add("Kabupaten Bantul")
                .Items.Add("Kabupaten Gunung Kidul")
                .Items.Add("Kabupaten Kulon Progo")
                .Items.Add("Kabupaten Sleman")
                .Items.Add("Kota Yogyakarta")
                .SelectedIndex = 0
            End With
        End If
    End Sub


3. If it is finished, double-click on button 3 (three) and type the code below. On button 3 (three), it contains validation where if the user clears one of the entries a notification message will appear:

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If TextBox1.Text = "" Then
            MsgBox("Please fill in your name first", vbInformation, "Gudio")
            TextBox1.Focus()
        ElseIf ComboBox1.Text = "" Then
            MsgBox("Your province must be filled", vbInformation, "Gudio")
            ComboBox1.Focus()
        ElseIf ComboBox2.Text = "" Then
            MsgBox("Your City Name must be filled in", vbInformation, "Gudio")
            ComboBox2.Focus()
        ElseIf TextBox2.Text = "" Then
            MsgBox("Your Zip Code is still empty", vbInformation, "Gudio")
            TextBox2.Focus()
        Else
            MsgBox("Here's Your Personal Data: " & vbCrLf & _
                    vbCrLf & _
                    "Your name : " & TextBox1.Text & vbCrLf & _
                    vbCrLf & _
                    "Your province: " & ComboBox1.Text & vbCrLf & _
                    vbCrLf & _
                    "Your city: " & ComboBox2.Text & vbCrLf & _
                    vbCrLf & _
                    "Your Zip Code: " & TextBox2.Text, vbInformation, "Gudio")
        End If
End Sub


4. Double-click on button 2, then type the following code:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        ComboBox1.SelectedIndex = -1
        ComboBox2.Items.Clear()
        TextBox1.Clear()
        TextBox2.Clear()
        TextBox1.Focus()
End Sub

This code is used to reset all fields.
Get used to using your fingers to type all the codes. Don't just copy and paste the code provided. The more often you type in the program code, the more you will understand about the code.
Try running the application that you created, the result is like this, if you correctly write all the code:

How to Make Chained Combo Box in Visual Studio

Okay, it's done, the simple chain combobox tutorial we made. Sorry, if the application in this tutorial is not good because I only give a simple example tutorial. For another time, I will share a tutorial on how to make chain combobox using a database.

If anyone wants to download, the full source code is here.


That's How to Make a Chain Combo Box Using Visual Studio, I hope you all, get the benefit of this tutorial. We meet again, at other times and with other interesting tutorials.
iklan related post
Load comments