none
Select a certain value from combobox RRS feed

  • Question

  • Suppose I have a combobox which contains the following items.

    Icecream

    Sandwich

    Burger

    Now, i have a label whose label text is "Sandwich". I want that when i click a button, the item "Sandwich" item should be selected in the combobox. How can we do this ?

    Tuesday, August 12, 2014 7:49 PM

Answers

  • Like this

    Public Class Form1
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Label1.Text = "Sandwich"
            ComboBox1.Items.AddRange({"Ice Cream", "Sandwich", "Burger"})
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            ComboBox1.SelectedItem = Label1.Text
        End Sub
    End Class

    • Proposed as answer by Solitaire Tuesday, August 12, 2014 11:21 PM
    • Marked as answer by Sid Williams Wednesday, August 13, 2014 7:47 AM
    Tuesday, August 12, 2014 8:14 PM