I've created a very simple view derived from CListView
, and I want to be able to show images on each column of my CListView
.
To do that I know that I have to use LVS_EX_SUBITEMIMAGES
and use SetItem
to set the Image in the sub item, simple as that, but not working.
all the code is here
void MyListView::OnInitialUpdate()
{
CListView::OnInitialUpdate();
//create the list control
GetListCtrl().ModifyStyle(0,LVS_REPORT | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP);
GetListCtrl().ModifyStyleEx(0,LVS_EX_SUBITEMIMAGES);
GetListCtrl().InsertColumn(0, _T("Column 1"), LVCFMT_LEFT,60);
GetListCtrl().InsertColumn(1, _T("Column 2"), LVCFMT_LEFT,60);
//load the images
CImageList *pImageList;
pImageList = new CImageList();
pImageList->Create( 26,26, ILC_MASK | ILC_COLOR16,2, 2);
CBitmap bitmap;
bitmap.LoadBitmap( IDB_MAIN);
pImageList->Add( &bitmap, (COLORREF)0xFFFFFF);
bitmap.DeleteObject();
bitmap.LoadBitmap( IDB_MAIN1);
pImageList->Add( &bitmap, (COLORREF)0xFFFFFF);
bitmap.DeleteObject();
GetListCtrl().SetImageList( pImageList, LVSIL_SMALL);
GetListCtrl().SetImageList( pImageList, LVSIL_NORMAL);
GetListCtrl().SetImageList( pImageList, LVSIL_STATE);
GetListCtrl().SetImageList( pImageList, LVSIL_GROUPHEADER);
COLORREF col;
col = RGB(240,240,240);
GetListCtrl().SetBkColor(col);
GetListCtrl().SetTextBkColor(col);
GetListCtrl().SetRedraw(TRUE);
//fill the view with 10 sample items
for (int i=0;i<10;i++)
{
CString csItem;
csItem.Format(L"Item %d",i+1);
GetListCtrl().InsertItem(LVIF_TEXT|LVIF_IMAGE,i,csItem,0,0,0,0);
CString csItem2;
csItem2.Format(L"Item2 %d",i+1);
GetListCtrl().SetItem(i,1,LVIF_TEXT|LVIF_IMAGE,csItem2,1,0,0,0,0);
}
}
It's really simple but I cannot get the result I want, and only the first column has images
I wanted that both columns had images, so the result should be like this
So what am I missing here? How can I correctly show the images also on the second column?
any help is apreciated, thanks in advance!