VB.NET: ComboBox Control Sample Project

Design UI

Code
 Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles MyBase.Load
        RadioButton1.Text = "DropDown"
        RadioButton2.Text = "DropDownList"
        RadioButton1.Select()
        ComboBox1.Items.Add("English")
        ComboBox1.Items.Add("Indonesian")
        ComboBox1.SelectedIndex = 0      
    End Sub

   
Private Sub RadioButton1_Click(ByVal sender As Object, _
      ByVal e As System.EventArgs) Handles RadioButton1.Click
        ComboBox1.DropDownStyle = ComboBoxStyle.DropDown
        ComboBox2.DropDownStyle = ComboBoxStyle.DropDown
    End Sub

   
Private Sub RadioButton2_Click(ByVal sender As Object, _
      ByVal e As System.EventArgs) Handles RadioButton2.Click
        ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList
        ComboBox2.DropDownStyle = ComboBoxStyle.DropDownList
    End Sub

   
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender _
      As System.Object, ByVal e As System.EventArgs) Handles _
      ComboBox1.SelectedIndexChanged
        ComboBox2.Items.Clear()
        Select Case ComboBox1.SelectedIndex
            Case 0
                With ComboBox2.Items
                    .Add("Monday")
                    .Add("Tuesday")
                    .Add("Wednesday")
                    .Add("Thursday")
                    .Add("Friday")
                    .Add("Saturday")
                    .Add("Sunday")
                End With
            Case 1
                With ComboBox2.Items
                    .Add("Senin")                      

                    .Add("Selasa")
                    .Add("Rabu")
                    .Add("Kamis")
                    .Add("Jumat")
                    .Add("Sabtu")
                    .Add("Minggu")
                End With
        End Select
        ComboBox2.SelectedIndex = Now.DayOfWeek - 1
    End Sub

End Class


Run Time



Click here if you like this article.


Artikel Terkait:
ComboBox Properties
ComboBox Event
ComboBox Control
Common Control Visual Basic.NET
Tutorial Visual Basic .NET

Contoh Project:
ComboBox Control Sample Project

Post a Comment

5 Comments

Unknown said…
mbak mau nanya saya mempunyai 2 combobox, combobox 1 memnaggil data dari database, combobox yg ke 2 memanggil data dari database juga tetapi berdasarkan combobox yang pertama.. itu bagaimana yah mbak? seperti combobox bertingkat? mohon penjelasan nya mbak., terima kasih
rani said…
binding combobox2 nya saat event combobox1 changed
Unknown said…
script nya seperti ini mbak, ini comboxbox yg ke 2 nya..?
di form load nya di buat juga mbak?

Private Sub cbo_departemen_SelectedValueChanged(sender As Object, e As EventArgs) Handles cbo_departemen.SelectedValueChanged
cbo_section.Enabled = True
If Not IsNothing(cbo_departemen.SelectedValue) Then
Dim idevision As Integer = cbo_devision.SelectedValue
Dim iddepartment As Integer = cbo_departemen.SelectedValue
rs = cn.Execute("SELECT distinct [department_code], [department_description] FROM [AN_SUMATRA].[dbo].[TM_tb_subsection] WHERE [devision_code]='" & idevision & "' and [department_code]='" & iddepartment & "' ORDER BY [department_code] ASC")
End If

End Sub

tetapi gak nampil dia
Unknown said…
mbak,apakah table nya harus berbeda beda?atau bisa satu table aja untk membaca database nya?
rani said…
semoga postingan ini bisa membantu
database nya pake access, silahkan disesuaikan sama database yang Panji pakai