CIconListBox - A list box with Icons
![]()
I needed a listbox showing Icons and text strings in our Application. When I didn't find any, I decided to create one. This List Box supports changing Icon for an item and removing the ImageList for the List Box at runtime.
How To Use It
To use this listbox class, simply drag a list box from the controls palette and drop it in the dialog Box. Set the properties Owner Draw style to Fixed or Variable, and with the Has Strings style checked.
Following are the steps to add a CIconListBox Class to a dialog:
- Add IconListBox.cpp and IconListBox.h to your project.
- Add include "IconListBox.h" to the header file of your dialog class.
- Use ClassWizard to add a member variable of control type for the List Box. Then replace the CListbox type with CIconListBox.
// in dialog.h //{{AFX_DATA(CIconLBDemoDlg) enum { IDD = IDD_ICONLBDEMO_DIALOG }; CIconListBox m_ListBox; //}}AFX_DATA
To set the ImageList, item text and/or Image, the overloaded public methods of CIconListBox Class are used:
int AddString(LPCTSTR lpszItem);
int AddString(LPCTSTR lpszItem, int iImg);
int InsertString(int iIndex, LPCTSTR lpszItem);
int InsertString(int iIndex, LPCTSTR lpszItem, int iImg);
void SetItemImage(int iIndex, int iImg);
inline void SetImageList(CImageList* pImgList = NULL)
{ m_pImageList = pImgList; }
In the demo application the Image list is set to List Box in the dialog's OnInitDialog() function. InitImageLists() method is the Dialog class function which is used to create the Image List.
// TODO: Add extra initialization here
InitImageLists();
m_ListBox.SetImageList(&m_imgNormal);
Downloads
Download demo project - 24 KbDownload source - 3 Kb

Comments
Set-/GetItemData() needs to be overwritten
Posted by Legacy on 01/30/2003 12:00amOriginally posted by: Kurt Santel�
This "tuned" listbox works great, except if you have already used the function SetItemData() for another purpose. Catching this function, and overwriting it would solve the problem. Or another way of storing which icon needs to be displayed is another solution.
greetz
ReplyKurt
Thanks Sekhar
Posted by Legacy on 11/11/2002 12:00amOriginally posted by: Mash
Was looking for implementing icons in the listbox.
This serves my purpose perfect.
ReplyIs it possible to use it in WinCE?
Posted by Legacy on 08/05/2002 12:00amOriginally posted by: Peter
Hi. I'm trying to use the class in application written in eMbedded Visual C++. Will it work? If it will, what should I add and where?
ReplyThanks in advance
how to do it in sdk
Posted by Legacy on 02/17/2002 12:00amOriginally posted by: deepak
It's good in MFC.
ReplyBut if I want to implement it in SDK?
How to do it?
Problem I used it but my first item in listbox does not display the right color?
Posted by Legacy on 02/01/2002 12:00amOriginally posted by: Mahshid
Hi, Thanks for the code. i followed the instruction in this page to add the Listbox, My first item in the list always display my third item in the list and it is not correct. Does anybody know what my mistake is?
ReplyThanks
Nice! One Change...
Posted by Legacy on 10/16/2001 12:00amOriginally posted by: Chris Adamson
ReplyEx(Properties)List
Posted by Legacy on 10/07/2001 12:00amOriginally posted by: Mike Philis
ReplyMultiSelect -> SelItemRange -> Disaster!!
Posted by Legacy on 09/20/2001 12:00amOriginally posted by: Raj
Hi
Excellent work!!
I'd like to point out a problem with your Iconic listbox.
1. List box style is made "Multiple" or "Extended"
2. Add a check box or any other toggle control to your dialog.
3. In the BN_CLICKED event of the above control, add the following code:
void CIconLBDemoDlg::OnCheck1()
{
int state = ((CButton*)GetDlgItem(IDC_CHECK1))->GetCheck();
CListBox* pListBox = (CListBox*)GetDlgItem(IDC_ICONLISTBOX);
pListBox->SelItemRange(state, 0, 5);
}
The bk color of the list box remains blue.. when we use SelItemRange.
Thankx
ReplyA free tool to rename an Existing Visual Studio project.
Posted by Legacy on 09/07/2001 12:00amOriginally posted by: Steven
UCanCode Just release a new version of toolbox,you can use it to rename an existing visual studio project or to backup an existing visual studio project.download a free copy by visit http://www.ucancode.net
Reply