Loading listview from dataset - what am I missing
-
Tuesday, August 21, 2012 12:54 PM
I am trying to load a listview from a data.
I am modifying code that was very slow. Took 5 seconds or so to load 99 rows with 8 columns.
I have the new code mostly working. The problem the columns are off by 1. Nothing is loading in the first column and what should be in the first column is displaying in the second column, etc...
I have had a couple of coworker look at the code and they didn't see any problem either.
Any help wouold be appreciated. Thanks in advance.
Dim lstLvi As New List(Of ListViewItem) For r = 0 To ds.Tables(0).Rows.Count - 1 Dim Lvi As New ListViewItem For c = 0 To ds.Tables(0).Columns.Count - 1 Lvi.SubItems.Add(ds.Tables(0).Rows(r).Item(c).ToString.Trim) Next lstLvi.Add(Lvi) Next lstFloat.Items.AddRange(lstLvi.ToArray())
All Replies
-
Tuesday, August 21, 2012 1:26 PM
Figured it out.
One of those Duh moments.
I was only adding subitems. I never added the item. Liek I said duh.
Here is the working code.
Dim lstLvi As New List(Of ListViewItem) For r = 0 To ds.Tables(0).Rows.Count - 1 Dim Lvi As ListViewItem = Nothing For c = 0 To ds.Tables(0).Columns.Count - 1 If c = 0 Then Lvi = New ListViewItem(ds.Tables(0).Rows(r).Item(c).ToString.Trim) Else Lvi.SubItems.Add(ds.Tables(0).Rows(r).Item(c).ToString.Trim) End If Next lstLvi.Add(Lvi) Next lstFloat.Items.AddRange(lstLvi.ToArray())
Thanks anyway. Maybe this will help someone else.
- Marked As Answer by Mark E Fowler Tuesday, August 21, 2012 1:26 PM
-
Wednesday, August 22, 2012 2:45 AMModerator
Hi Mark,
Congratulations.
Thank you for sharing your solution here.
Best regards,
Mike Feng
MSDN Community Support | Feedback to us
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

