Using ImageList with Listview Question
-
I have a app with a listview on a form set to detailsview. This works great but now I would like to add small image icons. In the listview controle is a "smallimagelist" property that is set to none and I can not change that...? Below is the code I use to populate the listview on load.... How can I modify my code to allow small icon view mode?
Public Sub ReloadListviewFromXML() Dim AddressBook As String = (Path.Combine(Application.StartupPath, "AddressBook.xml")) Dim ds As New DataSet Try ds.ReadXml(AddressBook) Dim dt As DataTable = ds.Tables("People") Dim i As Integer Dim j As Integer Me.listviewObjects.Items.Clear() For i = 0 To dt.Rows.Count - 1 Dim dr As DataRow = dt.Rows(i) With Me.listviewObjects .Items.Add(dr(0)) For j = 1 To dt.Columns.Count - 1 .Items(i).SubItems.Add(dr(j)) Next End With Next Catch ex As System.Exception End Try listviewObjects.GridLines = True listviewObjects.FullRowSelect = True listviewObjects.MultiSelect = True End Sub
Thanks...When people make you see red, be thankful your not colour blind.
-
I have a app with a listview on a form set to detailsview. This works great but now I would like to add small image icons. In the listview controle is a "smallimagelist" property that is set to none and I can not change that...? Below is the code I use to populate the listview on load.... How can I modify my code to allow small icon view mode?
Public Sub ReloadListviewFromXML() Dim AddressBook As String = (Path.Combine(Application.StartupPath, "AddressBook.xml")) Dim ds As New DataSet Try ds.ReadXml(AddressBook) Dim dt As DataTable = ds.Tables("People") Dim i As Integer Dim j As Integer Me.listviewObjects.Items.Clear() For i = 0 To dt.Rows.Count - 1 Dim dr As DataRow = dt.Rows(i) With Me.listviewObjects .Items.Add(dr(0)) For j = 1 To dt.Columns.Count - 1 .Items(i).SubItems.Add(dr(j)) Next End With Next Catch ex As System.Exception End Try listviewObjects.GridLines = True listviewObjects.FullRowSelect = True listviewObjects.MultiSelect = True End Sub
Thanks...When people make you see red, be thankful your not colour blind.
Hi Japel, You don't need to modify your code. Just add an imagelist from the toolbox to your form and add some images to it. Click on your listview and set the property 'SmallImageList' to the imagelist you've just added. However, if you want to use different images for different items in your listview, I suggest that you modify your code so that it uses ListviewItems. Regards, Nico