on a CDialog based dialog, I have a CTreeCtrl based control that contains
a
flat list of HTREEITEMs, each with a checkbox. When I add items to it
during
OnInitDialog, none of the checkboxes appear ticked, even though I set some
of them checked and stepping through the code suggests that they should
be.
That's a "quirk" of the control :)
The Platform SDK docs under the topic "Tree View Control Window
Styles" says:
"If you want to use this style, you must set the TVS_CHECKBOXES style
with SetWindowLong after you create the treeview control, and before
you populate the tree. Otherwise, the checkboxes might appear
unchecked, depending on timing issues.
"
Something like this is necessary:
BOOL CMyDialog::OnInitDialog()
{
CDialog::OnInitDialog();
/* Remove the style */
mTree.ModifyStyle( TVS_CHECKBOXES, 0 );
/* Now explicitly set it */
mTree.ModifyStyle( 0, TVS_CHECKBOXES );
HTREEITEM aItem = mTree.InsertItem("AAA");
mTree.SetCheck(aItem);
return TRUE;
}
The remove and add TVS_CHECKBOXES did the trick! Thanks.