I have a combobox assigned with a data source:
Public Sub DataBind(ByVal table As DataTable, ByVal DisplayMember As String, ByVal ValueMember As String)
cbox.DataSource = table
cbox.DisplayMember = DisplayMember
cbox.ValueMember = ValueMember
End Sub
I want to iterate each item in the ComboboxItems and get its ValueMember and DisplayMember. I watched this post ValueMember from ComboBox.Items[i] using WinForms c#
so I tried
For I As Integer = 0 To cbox.Items.Count - 1
Dim val = DirectCast(cbox.Items(I), KeyValuePair(Of Integer, String)).Value
Next
but I get an invalid cast exception saying that the specified cast is not valid. What am I doing wrong?