Icons in CListCtrl

Scattan
Scattan used Ask the Experts™
on
Hi!

I'm trying tp add an icon to my CListCtrl... it never shows up.
What am I doing wrong?

CImageList* m_pImage;
pImageList.Create(IDB_BITMAP1, 16, 16, RGB(255,0,255));
m_List.SetImageList(&pImageList, LVSIL_SMALL);

m_List.InsertColumn(0, _T("Name"),LVCFMT_LEFT,150);
m_List.InsertColumn(1, _T("Lastname"),LVCFMT_LEFT,150);

m_List.InsertItem(0, _T("Test"),0); //the first icon..
m_List.SetItemText(0, 1, _T("test"))

(IDB_BITMAP1 is a bitmap with height 16 and a row of pictures in it...) The text shows up - and it has left a place for the image..but it's empty!

Thanks!!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
there is something wrong with first two lines. Should be CImageList m_pImage;

or

CImageList* m_pImage = new CImageList;
m_pImageList->Create()

Author

Commented:
ok, sorry, this is what it looks like:

CImageList pImageList;
pImageList.Create(IDB_BITMAP1, 16, 16, RGB(255,0,255));
m_List.SetImageList(&pImageList, LVSIL_SMALL);

but the problam still remains..

Author

Commented:
ok, sorry, this is what it looks like:

CImageList pImageList;
pImageList.Create(IDB_BITMAP1, 16, 16, RGB(255,0,255));
m_List.SetImageList(&pImageList, LVSIL_SMALL);

but the problam still remains..
Commented:
Try 1 as the third parameter to create. Like this:
  pImageList.Create(IDB_BITMAP1, 16, 1, RGB(255,0,255));

Also, the image list needs to exist when the list box is drawn. As in, if you create the pImageList in OnInitDialog for example it will be erased once that function ends. Try to declare a member variable to your dialog instead and dynamically allocate the list in your InitDialog method.

In your mydialog.h file:
CImageList *m_pImageList

In your mydialog.cpp file ::OnInitDialog():
m_pImageList = new CImageList;
m_pImageList->Create(IDB_BITMAP1, 16, 1, RGB(255,0,255));

That should do it.

Other than that, what does your BMP look like?
And I assume you are displaying the list in report mode?

Cheers,
  Andre

Author

Commented:
Thank you!!
Ofcourse I had to have it in the h-file because it was deleted when exiting OnInitDialog().

Now it works fine!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial