Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why aren't my CTreeCtrl checkboxes checking?

Tags:

c++

windows

mfc

I've got a MFC CTreeCtrl stuck in a dialog with the TVS_CHECKBOXES style turned on. I get checkboxes next to all my tree items fine. In OnInitDialog I set the checked state of some of the items using CTreeCtrl::SetCheck but none of the items in the tree are checked when the tree is displayed. SetCheck is returning TRUE. Checking items with the mouse works fine. Anyone encounter this before?

like image 397
Brett Hall Avatar asked Aug 17 '09 18:08

Brett Hall


1 Answers

Figured out what the problems was. I was setting the TVS_CHECKBOXES style in the visual studio resource editor. Apparently this causes the problem I was having with the initial checks. Instead you have to do


   m_nodeTree.ModifyStyle (TVS_CHECKBOXES, 0);
   m_nodeTree.ModifyStyle (0, TVS_CHECKBOXES);

before filling the tree in OnInitDialog. Once I did this everything worked fine.

like image 139
Brett Hall Avatar answered Sep 28 '22 03:09

Brett Hall