And I started modifying the code. I found out there was a way to insert an icon in the Listbox control. This part of the code I have taken from Shripad Kulkarni's article Owner Draw Menus (including icons). All you have to do is to just follow the Procedure given by Sanjay Ahuja and start the project. Search Components, Applications, Add-ins and Cloud Services.
Hi Everone,
Can You please let me know how I can add icon(image) before items in a listbox.I have a simple code for listing database elements in a listbox and I would like to add icon for each element.For example a table icon before tables(like MS Access Table List or Ms SQL Server Object Explorer).
I am not sure if this possible but I realy apreciate your time if you can help me on this?
I am not sure if this possible but I realy apreciate your time if you can help me on this?
regards,
- 5 Contributors
- forum4 Replies
- 1,556 Views
- 2 Years Discussion Span
- commentLatest Postby macgurl70
Iam affraid you cannot put images into a listBox (without any additional hacking of the code).
I would better suggest you to use ListView, which is meant for it.8df
I would better suggest you to use ListView, which is meant for it.8df
Images to lsitview:
If you want to do this in the designer, you can take the following steps to add the images to the ListView control:
- Switch to the designer, click on the ImageList component on the Component Tray, there will be a smart tag appear on the top-right corner of the ImageList.
- Click the smart tag, and click 'Choose Images' on the pane.
- On the pop-up Image Collection Editor dialog, choose the images from the folder your want.
- Click OK to finish adding images to the ImageList.
- Click the ListView on the form, there will be a smart tag appear on the top-right corner.
- Click the smart tag, you will find there're three ComboBoxes there, choose a ImageList from the list as you want.
- Click the 'Add items' option on the smart tag, a ListViewItem Collection Editor will appear, you can add items to the ListView, it's important here to set the ImageIndex or ImageKey property, or the image won't appear.
- Click OK to finish item editing, now you'll find the images are displayed on the ListView.
If you want to add the images to the ListView by code, you can do something like this
![Codejock listbox icons Codejock listbox icons](/uploads/1/2/5/7/125772591/603470990.png)
Edited by Mitja Bonca: code added