
Very odd behavior with DataTable.Select
I think the select needs to look something like this
myTable.select("myColumn = '1234'")
notice the single quotes, therefore
mySelectString = "TypeCodeID = '" & ReferredByList.SelectedValue & '"
should work.
Btw, It sound like you're doing a select on the same table you've bound to
the combo. If so, you can get the selected row directly with...
dim r as datarow = ctype(myCombo.SelectedItem, DataRowView).row
Quote:
> Hello,
> I have a class that exposes a DataTable as a property. The class is
> derived from the ComboBox and the DataTable is what has been bound to
> the ComboBox control. I have one field of my DataTable set to the
> DisplayMember and another set to the ValueMember. I have a third field
> that I would like to access. I tried the following:
> ------------------
> Dim mySelectString As String
> Dim myRows As DataRow()
> mySelectString = "TypeCodeID = " & ReferredByList.SelectedValue
> myRows = ReferredByList.DataTable.Select(mySelectString)
> ------------------
> With this code I got an error that the DataRowView could not be
> converted to an integer. Next I tried:
> ------------------
> mySelectString = "TypeCodeID = " & ReferredByList.SelectedValue
> ("TypeCodeID")
> ------------------
> I received another error. While in debug mode I went to the immediate
> window and typed:
> ?ReferredByList.SelectedValue
> The immediate window showed a value of 32 (an integer...). Hmmmm, odd
> that it gave me an error. I changed the code back and got the error
> again. I went to the immediate window and typed:
> ?ReferredByList.SelectedValue("TypeCodeID")
> I got back a value of 32 (still an integer...). So, basically, whichever
> way I try to code it, it works the *other* way. If I switch my syntax it
> no longer works that way and the other way now seems to work.
> Any ideas on:
> 1. How to do something like this (i.e., get at a DataTable column for a
> ComboBox).
> 2. Why this odd behavior is occurring.
> Thanks,
> -Tom.