Notifications
Clear all

[Closed] Adding image to listView's subItems

Is there a way to add images in a listView’s subItems? I can only add an image in the 1st row right now.

(
     	rollout dialog_lvTest "LV test"
     	(
     		local imageFile = "C:\\Documents and Settings\\jlabbe\\Desktop\	estIcon.jpg"
     		
     		dotNetControl lv "System.Windows.Forms.ListView" width:480 height:480 align:#center
     		
     		on dialog_lvTest open do
     		(
     		-- Setup lv's properties	
     			lv.View = (dotNetClass "System.Windows.Forms.View").details
     			lv.gridLines = true
     			
     		-- Add columns	
     			columns = #("Object", "wireColor")
     			lv.columns.add columns[1] 230
     			lv.columns.add columns[2] 230
     			
     		-- Create image object	
     			imageList = dotNetObject "System.Windows.Forms.ImageList"
     			imageClass = dotNetClass "System.Drawing.Image"
     			imageList.images.add (imageClass.Fromfile imageFile)
     			
     		-- Add rows	
     			rows = #()
     			for obj in objects do
     			(
     				item = dotNetObject "System.Windows.Forms.ListViewItem" obj.name
     				item.subitems.add (obj.wireColor as string)
     				item.ImageIndex = 0
     				append rows item
     			)
     			lv.items.addRange rows
     			lv.SmallImageList = imageList
     		)
     	)
     	createDialog dialog_lvTest 500 500
     )
6 Replies

AFAIK, with the standard listview, you can’t add images to the subitems, just one per row.

2 Replies
(@denist)
Joined: 11 months ago

Posts: 0

it’s kinda true. by default only main item has an image. but there are couple ways how to add images to sub items. the most popular is to overwrite sub item drawing – add your own code to listView drawSubItem event…

(@system)
Joined: 11 months ago

Posts: 0

I was just going to have icons to use them as an item’s checked state. I’m aware you can actually replace the actual checkbox with an image, but listView doesn’t allow any checkboxes in its subItems.

Thanks, I’ll check that out.

… nooooo!

I guess the only decent solution would be to have 2 listViews?

Edit: This was my reaction when I read your response:
http://www.youtube.com/watch?v=phGzXh3z55c

Well, that’s one option, but it depends on what you are trying to do. Maybe doing something like using a flowlayoutpanel that you can fill with your own controls is an option? Or you could play around with the XtraTreeList thingy everyone’s been raving about, I’m pretty sure that can generate a listView with several images per row.

use “DevExpress.XtraTreeList.TreeList” control… it’s free for all max users.