我找不到正确的方法来使组合框中的第一项可见。
该应用程序从空的组合框开始。用户进行单选按钮选择,然后单击“Go!”(多么原始)。组合框通过LDAP查询加载。所有这些都正常工作。问题是,在用户看来,组合框仍然为空。他们必须单击箭头才能查看选项。
如何在用户点击“Go!”后使第一个选项“可见”?
我找不到正确的方法来使组合框中的第一项可见。
该应用程序从空的组合框开始。用户进行单选按钮选择,然后单击“Go!”(多么原始)。组合框通过LDAP查询加载。所有这些都正常工作。问题是,在用户看来,组合框仍然为空。他们必须单击箭头才能查看选项。
如何在用户点击“Go!”后使第一个选项“可见”?
' Your code filling the combobox '
...
If myComboBox.Items.Count > 0 Then
myComboBox.SelectedIndex = 0 ' The first item has index 0 '
End If
只需进入组合框属性 - DropDownStyle 并将其更改为“DropDownList”
这将使第一个项目可见。
或者
你可以在程序中写下这个
Private Sub ComboBoxExp_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles MyBase.Load
AlarmHourSelect.Text = "YOUR DEFAULT VALUE"
AlarmMinuteSelect.Text = "YOUR DEFAULT VALUE"
End Sub
Me.cbo1.Text = Me.Cbo1.Items(0).Tostring
If ComboBox1.SelectedIndex = -1 Then
ComboBox1.SelectedIndex = 0
End If
With Me.ComboBox1
.DropDownStyle = ComboBoxStyle.DropDown
.Text = " "
End With
设置DropDownList样式组合框的另一种好方法:
Combox1.SelectedIndex = Combox1.FindStringExact("test1")