Click here to Skip to main content
15,912,493 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Can anyone provide me a sample code for inserting an image in multiple columns of a list control in report view? The same image needs to be inserted in all cells of the column.
Posted

Use the CListCtrl::SetItem()[^] member to set the content for a particular item in the list.
 
Share this answer
 
i tried that... i added the one image in the image list as below:-

HIMAGELIST hList = ImageList_Create(16, 16, ILC_COLOR8 | ILC_MASK, 8, 1);
CImageList m_SmallImg;
m_SmallImg.Attach(hList);
CBitmap cBmp;
cBmp.LoadBitmap(IDB_CHECKBOX);
m_SmallImg.Add(&cBmp, RGB(255, 0 , 255));
cBmp.DeleteObject();
m_list.SetImageList(&m_SmallImg, LVSIL_SMALL);

// add to list control
m_list.SetItem(2, 5, LVIF_IMAGE, _T(""), 1, 0, 0, 0,0);
// 2nd item, 5th column, 1st image

All other cells with no images were correct. This didnt produce the image in the cell.
I have added acheck box image IDB_CHECKBOX in the res folder also.
is the "1" i gave in the SetItem() correct?
 
Share this answer
 
Comments
Richard MacCutchan 14-Aug-10 9:55am    
Please do not post questions as answers, I only discovered this by accident; if you have made an update then post a comment to the person whose answer you are referring to.

I think maybe your image index value should be 0 (zero) in your SetItem call, as the first image will be index 0 not index 1. Give it a try to see what happens.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900