我正在尝试在表单加载时设置客户详细信息,并在确保将组合框设置为正确的索引时遇到问题。
For iIndex As Integer = 0 To (Me.combo.Items.Count - 1)
If Me.combo.Items(iIndex).Key = customer.CustTypeId Then
Me.combo.SelectedIndex = iIndex
Exit For
End If
Next
Items.Key来自我试图转换为标准ComboBox的Klik控件。我试过访问Item的RowId但无济于事。
有谁能建议如何完成上述工作?
答案 0 :(得分:0)
你不能使用Collection.IndexOf方法吗?
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim one As String = "one"
Dim two As String = "two"
Dim three As String = "three"
Dim four As String = "four"
Dim five As String = "five"
ComboBox1.Items.Add(one)
ComboBox1.Items.Add(two)
ComboBox1.Items.Add(three)
ComboBox1.Items.Add(four)
ComboBox1.Items.Add(five)
MsgBox(ComboBox1.Items.IndexOf("three"))
End Sub
End Class