473,325 Members | 2,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

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 1306
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Martin Streller | last post by:
Hello, The code below represents a simple ownerdrawn, Listview class in C#. Its purpose is to avoid the flicker of the MS ListView. So I can't fall back to their one. Does anybody know why I...
2
by: MikeY | last post by:
Hi all, I am coding window forms in C#. My problem is this: I have created a "Check ListView" or a 'ListView' with checkbox's. I have populated the it with my files from my folders, mps, txt,...
2
by: Daniel | last post by:
I'm new to .Net and all of its abilities so I hope this makes sense. Basically I'm confused on when is the appropriate time to use web forms controls vs. regular HTML. For example in ASP...
5
by: yma | last post by:
Hello, I tried to display a column in MS Access 2000 nwind.mdb using 3 data controls. But I got "It is already opened exclusively by another user, or you need permission to view its data." I...
3
by: OpticTygre | last post by:
Are there any good tutorials out on the net that explains the listview control with great detail? Things like drag-drop features, icon additions, etc...?
1
by: OpticTygre | last post by:
I have a listview where users can add items via a textbox and an 'add' button. The problem is, the code below doesn't work for keeping duplicates entered. If I create a ListViewItem with the same...
1
by: Monty M. | last post by:
Does anyone know how to perform two way data binding between a combo box and a listview. The listview is bound to a dataset table in code: Binding Bind = new Binding(); DataTable dt;...
3
by: cr113 | last post by:
I'm trying to convert a windows app to ASP.NET using VS2005. I have some web experience, but not much. 99% of the time if I need to display data in a table in my windows apps I use a ListView...
0
by: William Johnston | last post by:
Hello, I actually read this: "The data bound to the DetailsView can be accessed via the DataItem property." How about for a ListView 3.5 control? I need to format my Eval calls to custom...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.