Posted 7 May 2020, 3:57 am EST
Hello,
I’m trying the C1ComboBox control. I’m binding datas to the combobox like this:
cmb.TranslateValue = True
cmb.ItemsDataSource = comboData
cmb.ItemsDisplayMember = "DisplayString"
cmb.ItemsValueMember = "ItemData"
Dim comboData As New BindingSource
comboData.Add(new ComboItem("string1",1)
comboData.Add(new ComboItem("string2",2)
...
When I try to iterate through all items and convert them as ComboItem, I’ve got an InvalidCastException: impossible to convert String to ComboItem:
For i = 0 To cmb.Items.Count - 1
If CType(cmb.Items.Item(i), ComboItem).ItemData = Itemdata Then
cmb.SelectedIndex = i
Exit Sub
End If
Next i
ComboItem class
Public Class ComboItem
Public Property DisplayString As String
Public Property ItemData As Object
Public Sub New(displayString As String, Optional itemData As Object = Nothing)
Me.DisplayString = displayString
Me.ItemData = itemData
End Sub
End Class
How can I get the object and not just the string?