Discussion:
Problem with inserting images as items in CListCtrl
(too old to reply)
b***@yahoo.com
2006-05-24 17:27:56 UTC
Permalink
I want to insert images in ListCtrl throgh resource editor.
In OnCREATE of CDialog Derived class ......
Here is the code .Tell me where I am going wrong

CImageList *m_pImageList;
m_pImageList = new CImageList();

m_myListCtrl.InsertColumn(0,TEXT("aaaa"));
m_myListCtrl.InsertColumn(1,TEXT("bbbb"));
m_myCtrl.InsertColumn(2,TEXT("cccc"));

m_myListCtrl.SetColumnWidth(0, 100);
m_myListCtrl.SetColumnWidth(1, 100);
m_myListCtrl.SetColumnWidth(2, 100);

ASSERT(m_pImageList != NULL); // serious allocation failure checking
m_pImageList->Create(32, 32, TRUE, 4, 4);

m_pImageList->Add(AfxGetApp()->LoadIcon(IDI_ICON1));
m_pImageList->Add(AfxGetApp()->LoadIcon(IDI_ICON2));
m_myListCtrl.SetImageList(m_pImageList, LVSIL_SMALL);

I get assertion problem at creation of m_pmyLISTctRL;
I am not able to figure it out

afxcmn.inl line no194
{ ASSERT(::IsWindow(m_hWnd)); return (int) ::SendMessage(m_hWnd,
LVM_INSERTCOLUMN, nCol, (LPARAM)pColumn); }
b***@yahoo.com
2006-05-24 17:54:31 UTC
Permalink
I added this code in oninitdialog then it started working ,but images
are missing ,
can some one help me here.
thanks
Ajay Kalra
2006-05-24 18:08:59 UTC
Permalink
OnCreate is not going to be called for a dialog. Use OnInitDialog
instead. You can create/initialize the imagelist in Dialog's
constructor if you want.

---
Ajay
b***@yahoo.com
2006-05-24 18:54:22 UTC
Permalink
I added the code inOnInitDilaog so no assertion but images are
invisible.
:-(
b***@yahoo.com
2006-05-24 18:59:12 UTC
Permalink
I created the list control with view set to small icon .
Is that I am missing basics ?
John Smith
2006-05-25 15:02:01 UTC
Permalink
Yes - you need to:

1. create & populate a CIMageList object
2. call CListCtrl::setImageList(...) with the initialized object
3. use image index when calling CListCtrl::InsertItem
Post by b***@yahoo.com
I created the list control with view set to small icon .
Is that I am missing basics ?
Loading...