|
-
Jul 8th, 2008, 10:06 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Adding Image to ListView - Problem
Hi guys,
I'm working on a dynamic listview from Sql server 2k database, and I need to add image on it. I already added ImageList control to my form, and set the ListView property as LargeIcon, SmallImageList as the ImageList.
I do not know how to add image on the listview. Here is my code and I dont know what's wrong with it, though it shows the data from database, only the image is not appearing:
Code:
Public Sub PopulateListView_Images(ByVal lv As ListView, ByVal cmd As SqlCommand, ByVal myImageList As ImageList)
Dim da As New SqlDataAdapter
Dim ds As New DataSet
ds.Reset()
da = New SqlDataAdapter(cmd)
da.Fill(ds)
'Fill Method
lv.Columns.Clear()
lv.Items.Clear()
lv.SmallImageList = myImageList
'Fill Listview
Dim c As DataColumn
For Each c In ds.Tables(0).Columns
'adding names of columns as Listview columns
Dim h As New ColumnHeader
h.Text = c.ColumnName
h.Width = 60
lv.Columns.Add(h)
Next
Dim dt As DataTable = ds.Tables(0)
Dim str(ds.Tables(0).Columns.Count) As String
'adding Datarows as listview Grids
Dim rr As DataRow
For Each rr In dt.Rows
For col As Integer = 0 To ds.Tables(0).Columns.Count - 1
str(col) = rr(col).ToString()
Next
Dim ii As New ListViewItem(str)
lv.Items.Add(ii)
'showing the number of records still added
Next
End Sub
In this code, only the data is showing but no image. I tried adding
Code:
lv.Items(0).ImageKey = 0
but it does not work too.
This is now my table structure:
Code:
SubModule Char 100
Icon Int 4
Only the SubModule name appears. What I need is that the value of "Icon" (0,1,2,3) is dynamic to lv.Items(0).imagekey
Please help me on how to add image on the listview. You can advice me also if my code above is wrong.
Thank you.
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
|