|
-
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.
-
Jul 8th, 2008, 10:15 PM
#2
Hyperactive Member
Re: Adding Image to ListView - Problem
Ive never really tampered with listview that much except to add rows and such for an extraction process but these links might be of use to you:
1. http://www.sellsbrothers.com/askthew...inlistview.htm
2. http://www.developerfusion.co.uk/show/125/
3. http://www.java2s.com/Tutorial/VB/02...leListview.htm
-
Jul 8th, 2008, 10:25 PM
#3
Re: Adding Image to ListView - Problem
First up, an ImageList is not a control. It's a component.
A ListView gets all its Images from the associated ImageLists. To add a new Image to the ListView you must first add it to the appropriate ImageList, then set the ImageIndex or ImageKey of one or more items to display that Image.
-
Jul 8th, 2008, 11:45 PM
#4
Re: Adding Image to ListView - Problem
Well actually you will need to add your images to the Imagelist first and then set it to the Listview and when adding Listview items you can specify the image index to use for each item.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 9th, 2008, 01:49 AM
#5
Re: Adding Image to ListView - Problem
Hi,
Here's is some explanation about a listview and an Imagelist.
http://msdn.microsoft.com/en-us/libr...imagelist.aspx
Wkr,
sparrow1
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
|