Skip to main content

Two drop down lists one for country name and another for President / Head of the country in VB.NET.

DESCRIPTION: 
When user selects a country name from combo box,corresponding President/Head name should be displayed in another combo box.Click the button textbox text add to combo box.
PROPERTIES:
Label1
TextCOUNTRY NAME
Label1
TextPRESIDENT NAME
ComboBox1
Text COUNTRY
ItemsINDIA
U.S.A
U.A.E
RUSSIA
ComboBox2
Text PRESIDENT|HEAD
ItemsNarendra Modi
Donald Trump
Khalifa bin Zayed Al Nahyan
Vladimir Putin
TextBox1
Text(Empty)
Button1
TextADD COUNTRY
CODEING:
Public Class Form1
    Dim country As String
    Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
        ComboBox2.SelectedIndex = ComboBox1.SelectedIndex
        Label2.Text = "PRESIDENT OF " & ComboBox1.Text

    End Sub
    Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged
        ComboBox1.SelectedIndex = ComboBox2.SelectedIndex
        Label2.Text = "PRESIDENT OF " & ComboBox1.Text

    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If Button1.Text = "ADD COUNTRY" And Not TextBox1.Text = "" Then
            country = TextBox1.Text
            Button1.Text = "HEAD OF " & country
            TextBox1.Clear()
        ElseIf Not TextBox1.Text = "" Then
            ComboBox2.Items.Add(TextBox1.Text)
            ComboBox1.Items.Add(country)
            Button1.Text = "ADD COUNTRY"
            TextBox1.Clear()
        End If
    End Sub
End Class
DESIGNING:




Comments