how to add value to combobox item

后端 未结 6 691
半阙折子戏
半阙折子戏 2020-12-14 04:47

How can I add data value of each item to combobox in Visual Basic 2010?

Like html drop-down box.

Or is there anyway to add values to each item ?

I am

6条回答
  •  半阙折子戏
    2020-12-14 05:12

    Although this question is 5 years old I have come across a nice solution.

    Use the 'DictionaryEntry' object to pair keys and values.

    Set the 'DisplayMember' and 'ValueMember' properties to:

       Me.myComboBox.DisplayMember = "Key"
       Me.myComboBox.ValueMember = "Value"
    

    To add items to the ComboBox:

       Me.myComboBox.Items.Add(New DictionaryEntry("Text to be displayed", 1))
    

    To retreive items like this:

    MsgBox(Me.myComboBox.SelectedItem.Key & " " & Me.myComboBox.SelectedItem.Value)
    

提交回复
热议问题