[RESOLVED] add icon to Listview subitem
I have a Listview showing an archive of documents.
I want to add an icon to a subitem when the document was add after my last login. So I know what is new
Code:
If dr("Id") > iLast Then
docImage2 = ImageList1.Images.Count
items.Add(New ListViewItem(New String() {"", dr("Document Name").ToString & docImage2, dr("DISnummer").ToString, dr("XPostnummer").ToString, dis, dr("Id").ToString, dr("Document Location").ToString}, docImage))
End If
The code doesnt work. It only adds the number 5 after the text.
Is is not possible to add icons to subitems?
Re: add icon to Listview subitem
Does the documentation indicate anywhere that you can add icons to subitems? If you want to know how a type or member works then you should ALWAYS read the documentation for that type or member and any relevant related topics. That is something that you should always have done before posting here. Don't ignore information that has been specifically created to help you and is only a click or two away.
There's far more information besides this but simply looking at the property lists for the ListViewItem and ListViewSubItem classes should pretty much answer your question.
Re: add icon to Listview subitem
No, the Listview doesn't support images in any column other than the first column (details view). However, if you were in a masochistic mood you could set the ListView.OwnerDraw Property to True and draw your own image in which ever cell you like.
Might make more sense to use a DataGridView instead of a ListView, especially as you seem to be getting your data from a DataTable. DataTables can be data bound to DataGridViews and any column in the DataGridView can be an Image Column.
Re: add icon to Listview subitem
On the standard MS listview control you can not add icons to any other column then the first. You can trick it by setting the icon to the first but reorder the column so it appears as a non-first column. Still only one column can have icons. You can use APIs to modify this behavior or use a third party control.