Dataview problems [resolved]
Okay, I have two combo boxes on a form, both displaying a different column from the same datatable, I want both these combo boxes to be sorted alphabetically though, so I created a dataview as so
VB Code:
ds.Tables.Add("ContactsCom")
ddiView = New DataView(ds.Tables("ContactsCom"))
I then bind the combo boxes as follows
VB Code:
Me.cbocompany.DataSource = ds
Me.cbocompany.DisplayMember = "ContactsCom.CompanyName"
Me.cbocompany.ValueMember = "ContactsCom.ContactID"
ddiView.Sort = "MID"
cboddi.DataSource = ddiView
Me.cboddi.DisplayMember = "MID"
Me.cbocompany.ValueMember = "ContactID"
Which all seems to work fine, but my problem now is that on the
cbocompany combo box this works
VB Code:
Private Sub cbocompany_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbocompany.SelectedIndexChanged
Try
MsgBox(cbocompany.SelectedValue)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
But on the cboddi box I get the exception
VB Code:
Private Sub cboddi_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboddi.SelectedIndexChanged
Try
MsgBox(cboddi.SelectedValue)
Catch ex As Exception
Me.TextBox1.Text = ex.ToString
End Try
End Sub
System.ArgumentException: Argument 'Prompt' cannot be converted to type 'String'.
Why?