<h2>Question</h2> I am using a tree control in my eVC application. I want to display checkboxes for the tree items. I have selected checkbox option in the properties dialog but when I added nodes to the tree it is not displaying checkboxes. How can I fix it?
<h2>Answer</h2> By some reason the tree control shows checkboxes only when an image list is assigned. If you do not need images in the tree control you can create a dummy image list with images that look like checkboxes.
<h2>Step by step</h2> <ol> <li>Add CTreeCtrl and set "Check Boxes" flag in the control properties (or add <i>TVS_CHECKBOXES</i> style)</li> <li>Create new bitmap resource with the attached picture - <a href="/articles/samples/checkbox.bmp">checkbox.bmp</a>
</li> <li>Add CImageList member variable to your class declaration like:
Code:
CImageList m_il;
</li> <li>Create an image list using the bitmap resource in the initialization function:
Code:
m_il.Create(IDB_CHECKBOX, 16, 0, CLR_NONE);
</li> <li>Assign this image list to the tree control:
Code:
m_ctrlTree.SetImageList(&m_il, TVSIL_STATE);
</li> </ol>
<h2>Sources</h2> You can download a sample project with sources - <a href="/articles/samples/CheckboxTree.zip">CheckboxTree.zip</a> (18Kb).