156k views
0 votes
Write a program in vb.net to select college using single combo box.


\\ \\ \\ \\ \\

\boxed{ \color{white} \large\textsf{Thank You! }}


User Te
by
6.5k points

1 Answer

4 votes

Answer:

Public Class Form1

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

'Add items to the combo box

cboCollege.Items.Add("College of Engineering")

cboCollege.Items.Add("College of Business")

cboCollege.Items.Add("College of Arts and Sciences")

cboCollege.Items.Add("College of Education")

End Sub

Private Sub cboCollege_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboCollege.SelectedIndexChanged

'Display the selected college

lblCollege.Text = "You selected " & cboCollege.SelectedItem.ToString()

End Sub

End Class

Step-by-step explanation:

In this program, a single combo box named cboCollege is added to the form. When the form loads, the Form1_Load event handler adds four items to the combo box representing different colleges. When the user selects an item in the combo box, the cboCollege_SelectedIndexChanged event handler is triggered, which displays the selected college in a label named lblCollege.

Note that the SelectedItem property of the combo box is used to retrieve the selected item as a string. Also, the ToString() method is used to convert the selected item to a string, since the SelectedItem property returns an Object.

User Igor Mukhin
by
7.1k points