469,609 Members | 1,182 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,609 developers. It's quick & easy.

Help with Data bound ListView

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!!
Nov 21 '05 #1
2 1227
oops.. spelling mistake... Error should "cast" not "case" 'dataviewrow' to 'string'..
"Simon Verona" <ne**@aphroditeuk.com> wrote in message news:eM**************@TK2MSFTNGP09.phx.gbl...
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!!
Nov 21 '05 #2
Problem solved!!

Curiously I found that setting the datasource after setting the ValueMember and DataMember seems to do the trick - I'm not sure why!!

Regards
Simon
"Simon Verona" <ne**@aphroditeuk.com> wrote in message news:eV**************@TK2MSFTNGP10.phx.gbl...
oops.. spelling mistake... Error should "cast" not "case" 'dataviewrow' to 'string'..
"Simon Verona" <ne**@aphroditeuk.com> wrote in message news:eM**************@TK2MSFTNGP09.phx.gbl...
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!!
Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Martin Streller | last post: by
2 posts views Thread by Daniel | last post: by
3 posts views Thread by OpticTygre | last post: by
1 post views Thread by OpticTygre | last post: by
3 posts views Thread by cr113 | last post: by
reply views Thread by William Johnston | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.