Hi
Here is an MFC noob question.
I have a CTreeCtrl with TVS_CHECKBOXES set.
In OnInitDialog I populate the tree with a set of rules grouped into packages and groups, and I wish to preset a selection. The tree is populated ok but with no items checked. I can check items in the GUI and read that state ok, but my pre-sets are gone.
This is the code (well, parts of it):
OnInitDialog()
{
__super::OnInitDialog();
PopulateTree();
return TRUE;
}
PopulateTree ()
{
mRulesTree.DeleteAllItems();
ParseRulesFile();
mRulesTree.ModifyStyle( 0, TVS_CHECKBOXES );
std::string package = mRulesList[0]->package;
std::string group = mRulesList[0]->group;
HTREEITEM currPackage = mRulesTree.InsertItem( package.c_str(), NULL );
HTREEITEM currGroup = mRulesTree.InsertItem( group.c_str(), currPackage );
HTREEITEM currRule;
for ( size_t i = 0; i < mRulesList.size(); ++i )
{
if ( mRulesList[i]->package != package )
{
package = mRulesList[i]->package;
currPackage = mRulesTree.InsertItem( package.c_str(), NULL );
}
if ( mRulesList[i]->group != group )
{
group = mRulesList[i]->group;
currGroup = mRulesTree.InsertItem( group.c_str(), currPackage );
}
std::string ruleDesc = mRulesList[i]->name + " - " + mRulesList[i]->synopsis;
currRule = mRulesTree.InsertItem( mRulesList[i]->name.c_str(), currGroup );
if ( mSelectedRules.size() != 0 )
{
if ( std::find( mSelectedRules.begin(),
mSelectedRules.end(),
mRulesList[i]->name ) !=
mSelectedRules.end() )
{
mRulesTree.SetCheck( currRule, true );
}
}
else
{
mRulesTree.SetCheck( currRule, mRulesList[i]->default_on );
}
}
}
and this is from the resource file:
IDD_RULES_SETTINGS_DLG DIALOGEX 0, 0, 300, 300
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Rules Settings"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
LTEXT "RULES",IDC_STATIC,7,8,32,8
CONTROL "",IDC_RULES_SETTINGS_TREE,"SysTreeView32",TVS_HASLINES | TVS_HASBUTTONS | TVS_CHECKBOXES | TVS_LINESATROOT | TVS_SHOWSELALWAYS | WS_BORDER | WS_HSCROLL | WS_TABSTOP,14,20,273,245
DEFPUSHBUTTON "OK",IDOK,189,280,50,14
PUSHBUTTON "Cancel",IDCANCEL,243,280,50,14
END
Regards
Robert