tags:

views:

306

answers:

2

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?

+1  A: 

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.

Brett Hall
A: 

It's amazing!

I created myTreeCtrl using myTreeCtrl.Create(WS_CHILD|TVS_HASBUTTONS|TVS_CHECKBOX|, CtrlRect, this, IDC_TREECTRL); I tried to check some items in OnInitialDialog() and had the same problems. I tried myTreeCtrl.ModifyStyle(TVS_CHECKBOXES, 0); myTreeCtrl.ModifyStyle(0, TVS_CHECKBOXES); , and now it works fine. More, it didn't check the item if it was not in the visible part of the window. I had to put a trigger on OnVScroll().

Rita