S
Simon Verona
I'm trying to create a dataview in code and bind it to a combobox using the code below.
When it gets to setting the txtLookup.ValueMember="id" in the code an error message of "unable to case dataviewrow to string" appears... and I can't work out why! Can anybody help?
Thanks.. Simon
=== Code ====
dt = New DataTable
ds = New DataSet
dv = New DataView
dt.TableName = "Data"
dt.Columns.Add("Id", System.Type.GetType("System.String"), "")
dt.Columns.Add("Description", System.Type.GetType("System.String"), "")
Dim dr As DataRow
For cnt = 1 To dct
If jtmp.Extract(m_LookupAmc, cnt).StartsWith("*") = False Then
dr = dt.NewRow
dr.Item("Id") = CStr(cnt)
dr.Item("Description") = CStr(jtmp.Extract(m_LookupAmc, cnt))
dt.Rows.Add(dr)
End If
Next cnt
ds.Tables.Add(dt)
dv = ds.Tables("Data").DefaultView
dv.Sort = "Description"
txtLookup.DataSource = dv
txtLookup.DisplayMember = "Description"
txtLookup.ValueMember = "Id" '<<<<< It crashes out here!!
When it gets to setting the txtLookup.ValueMember="id" in the code an error message of "unable to case dataviewrow to string" appears... and I can't work out why! Can anybody help?
Thanks.. Simon
=== Code ====
dt = New DataTable
ds = New DataSet
dv = New DataView
dt.TableName = "Data"
dt.Columns.Add("Id", System.Type.GetType("System.String"), "")
dt.Columns.Add("Description", System.Type.GetType("System.String"), "")
Dim dr As DataRow
For cnt = 1 To dct
If jtmp.Extract(m_LookupAmc, cnt).StartsWith("*") = False Then
dr = dt.NewRow
dr.Item("Id") = CStr(cnt)
dr.Item("Description") = CStr(jtmp.Extract(m_LookupAmc, cnt))
dt.Rows.Add(dr)
End If
Next cnt
ds.Tables.Add(dt)
dv = ds.Tables("Data").DefaultView
dv.Sort = "Description"
txtLookup.DataSource = dv
txtLookup.DisplayMember = "Description"
txtLookup.ValueMember = "Id" '<<<<< It crashes out here!!