I am trying to display multiple icons to the Treeview item but it is not displaying all the icons, it displays only one. I am using the following code:
CImageList m_imageState;
m_c开发者_如何转开发Tree.m_imageState.Create(16, 16, ILC_MASK, 0, 4);
m_cTree.m_imageState.Add(&bm, RGB(255,255,0));
m_cTree.m_imageState.Add(&bm2, RGB(255,0,255));
m_cTree.m_imageState.Add(&bm, RGB(255,255,0));
m_cTree.m_imageState.Add(&bm1, RGB(0,255,255));
m_cTree.SetImageList( &(m_cTree.m_imageState), TVSIL_NORMAL );
But when I see Treeview, item displays only one icon. Is it possible to display multiple icons with Treeview item?
Please suggest how can I do this.
Correct, only one icon will be displayed per item in a TreeView
control. This is by design, a hard limitation of the native control that the MFC library wraps.
The only way you're going to be able to display multiple icons per item is owner drawing. It's a pretty difficult task for a TreeView
control, not nearly as easy as owner drawing a button or a label control. Make sure that you really this need this functionality, and consider whether there's a better way of displaying the relevant information to your users.
Alternatively, you could create custom bitmaps that combine multiple images next to one another, and add those to your ImageList
. The resulting images will be wider than they are tall, but the control doesn't care: it will display whatever size images you specify, as long as all the images in the image list have the same dimensions. This is definitely a hack, but it might work, depending on your needs.
精彩评论