|
-
Jan 24th, 2011, 10:53 AM
#1
Thread Starter
Lively Member
[RESOLVED] Strange imageIndex problem
I have a ListView (lvwDocs) which has 2 columns (DocLink and ID). Here's the code I'm using to populate the ListView:
Code:
Do While dataReader.Read
itmListItem = New ListViewItem()
itmListItem.Text = dataReader(0)
For shtCounter = 1 To dataReader.FieldCount() - 1
If dataReader.IsDBNull(shtCounter) Then
itmListItem.SubItems.Add("")
Else
itmListItem.SubItems.Add(dataReader(shtCounter))
End If
Next shtCounter
lvwDocs.Items.Add(itmListItem)
This populates all columns and all rows as expected.
However, I want to add an icon next to each row. To achieve that, I change the last line of the code to:
Code:
lvwDocs.Items.Add(itmListItem.Text, nIndex)
The variable nIndex is initialised to 0 before the Do While loop. This successfully adds the desired icon, however, the 2nd ListView column is no longer populated, only the first column. Can anyone help get both columns populated, as per the 1st example, as well as the icon?
-
Jan 24th, 2011, 10:59 AM
#2
Re: Strange imageIndex problem
It's because you are using an overload of the Add method that is creating the ListViewItem for you. Try this:
Code:
Do While dataReader.Read
itmListItem = New ListViewItem()
itmListItem.Text = dataReader(0)
itmListItem.ImageIndex = nIndex
For shtCounter = 1 To dataReader.FieldCount() - 1
If dataReader.IsDBNull(shtCounter) Then
itmListItem.SubItems.Add("")
Else
itmListItem.SubItems.Add(dataReader(shtCounter))
End If
Next shtCounter
lvwDocs.Items.Add(itmListItem)
Loop
-
Jan 24th, 2011, 11:07 AM
#3
Thread Starter
Lively Member
Re: Strange imageIndex problem
Crap, yeah, didn't spot the overload. Cheers, that works perfectly.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|