News | Articles | Libraries | Developer Tools | Books | Forum Links | Search   
Sections:
 

QA: How can I create a tree control with checkboxes?

By Vassili Philippov, May 16, 2002.
Print version

Question

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?

Answer

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.

Step by step

  1. Add CTreeCtrl and set "Check Boxes" flag in the control properties (or add TVS_CHECKBOXES style)
  2. Create new bitmap resource with the attached picture - checkbox.bmp
  3. Add CImageList member variable to your class declaration like: CImageList m_il;
  4. Create an image list using the bitmap resource in the initialization function: m_il.Create(IDB_CHECKBOX, 16, 0, CLR_NONE);
  5. Assign this image list to the tree control: m_ctrlTree.SetImageList(&m_il, TVSIL_STATE);

Sources

You can download a sample project with sources - CheckboxTree.zip (18Kb).

Discuss

Discuss this article. Here you can write your comments and read comments of other developers.
Rate this article:     Poor Excellent    
 12345 
© 2001-2005 Pocket PC Developer Network, a division of Spb Software House