Reputation: 97
I want to set image only in particular rows of listctrl.
If I use CListCtrl's SetImageList, it is setting image in first column of each row.
Is it possible to set image only in whichever row I want.
Upvotes: 1
Views: 1837
Reputation: 347
A simple way to achieve it is adding a transparent image in your CImageList and set it on the list item you don't want the image to appear.
Upvotes: 0
Reputation: 243
I think it's a little bit messy but it works for me.
If your CListCtrl has LVS_OWNERDRAWFIXED style, than you can decide which column which image will have. For this purpose you need to set extended style LVS_EX_SUBITEMIMAGES for your list after it will be created. Than you add CImageList field to your CListCtrl-derived class, for example it will have m_imgList name. This field has to be initialized with default values and with image resource that will be using. After that you have to call SetImageList and pass it m_imgList. As long as your list will have LVS_OWNERDRAWFIXED style you need to implement DrawItem function in which you will call something like this for image drawing:
LVITEM lvItem = {0};
lvItem.mask = LVIF_IMAGE;
lvItem.iSubItem = nCol; // column index
lvItem.iItem = nItem; // item index
GetItem(&lvItem);
POINT p; // init it like you want
pDC // pointer on device context
m_imgList.Draw(pDC, lvItem.iImage, p, ILD_MASK);
And before that, when you will fill the list with values, you have to fill in LVITEM structure for needed column:
LVITEM lvItem = {0};
lvItem.iItem = nItem; // item index
lvItem.iSubItem = i; // column index
lvItem.iImage = nImg; // image index from imageList
lvItem.mask = LVIF_IMAGE;
And after that you have to call InsertItem or SetItem with this lvItem parameter.
Upvotes: 1