Problems binding data to ListView Control

S

SiewSa

Attached herewith part of my code for your references. My code is working
fine in normal dotnet frameworks but it's giving me errors while I am
applying the same way in Compact Framework.

ListView1.Items.Clear()

With myDataSet1.Tables("Table")

For intCounter = 0 To .Rows.Count - 1 Step 1

ListView1.Items.Add(.Rows(intCounter).Item(0).ToString) 'ERROR

ListView1.Items(intCounter).SubItems.Add(.Rows(intCounter).Item(1).ToString)

ListView1.Items(intCounter).SubItems.Add(.Rows(intCounter).Item(2).ToString)

ListView1.Items(intCounter).SubItems.Add(.Rows(intCounter).Item(3).ToString)

ListView1.Items(intCounter).SubItems.Add(.Rows(intCounter).Item(4).ToString)

ListView1.Items(intCounter).SubItems.Add(.Rows(intCounter).Item(5).ToString)



Next

End With



With the above coding, I was prompted with the error that saying String
datatype cannot be converted to ListViewItem. I have gone through a lot of
testings but still cannot get it done. Can anyone out there share with me
the code to binding data for listview control in Compact framework? Real
appreciate that! Thanks.
 
P

Peter Foot [MVP]

You cannot add a string to the Items collection - instead you must create a
new ListViewItem and populate its Text and SubItems. You'll probably also
find the control updates faster if you create a new ListViewItem and
populate all the subitems before adding it to the list.


ListView1.Items.Clear()

With myDataSet1.Tables("Table")

For intCounter = 0 To .Rows.Count - 1 Step 1

Dim lviNew As New ListViewItem(.Rows(intCounter).Item(0).ToString)

lviNew.SubItems.Add(.Rows(intCounter).Item(1).ToString)

'repeat for each column required

ListView1.Items.Add(lviNew)



Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top