Problems binding data to ListView Control

  • Thread starter Thread starter SiewSa
  • Start date Start date
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.
 
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
 
Back
Top