From: GT on
Short version:
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.

Calling the same code dynamically after the OnInitdialog has finished and
the items do get ticked.

Help!

Long version:
I have a dialog in my application that allowed the user to turn on and off
various options. There are 2 tree controls on the dialog. The tree on the
left has fixed content - an entry for each of the 8 areas of my application
and is populated in my OnInitDialog. The tree on the right is populated on
demand and contains a flat list of entries relevant to any one section of my
application. Each entry on the right hand tree has a checkbox. My current
set of checks is defined in a 2d bool array called m_bColumnView. All are
CTreeCtrl + CDialog derivatives.

In my OnInitDialog, I populate the tree on the left and that works OK (there
are no checkboxes). I also default the tree on the left to the first
section, which triggers my OnTvnSelchangedTree event operation, which does a
few basic checks, then calls my PopulateList() operation to populate the
tree on the right, thereby giving the dialog some default entries. The
PopulateList method creates a mask:

UINT iMask = TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_PARAM;

Then adds a series of tree items with checkboxes, therefore, I have a series
of lines like this:

m_treeRHS.SetCheck(m_treeRHS.InsertItem(iMask, "Name", 2, 2, NULL, NULL,
col_name, TVI_ROOT, NULL), m_bColumnView[m_iTreeItem-1][col_name]);

When I click through the sections on the left the tree on the right is
populated by PopulateList() and behaves perfectly, but when I trigger
PopulateList() during my OnInitDialog, the tree on the right is populated
with all the right entries, but no checkboxes are tickes. I have stepped
through the code and they definitely should be ticked, they just don't
appear ticked on the screen.

Any idea whats going on??


From: GT on
"GT" <a(a)b.c> wrote in message
news:4bf54da8$0$24683$c3e8da3(a)news.astraweb.com...
> Short version:
> 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.
>
> Calling the same code dynamically after the OnInitdialog has finished and
> the items do get ticked.
>
> Help!

Forgot to add - Visual Studio 2005. C++, MFC.


From: Tom Serface on
Any chance you've got some pointer or reentrancy problems? You could be
using the same routine to set both and they are just getting their signals
crossed.

Also, and you probably thought of this already, make sure they are both set
up the same.

Do you have a routine that is managing a hittest and setting some value
either in the data of the tree item or some externally stored array? If so,
maybe one is affecting the other?

Just some ideas.

Tom

"GT" <a(a)b.c> wrote in message
news:4bf54da8$0$24683$c3e8da3(a)news.astraweb.com...
> Short version:
> 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.
>
> Calling the same code dynamically after the OnInitdialog has finished and
> the items do get ticked.
>
> Help!
>
> Long version:
> I have a dialog in my application that allowed the user to turn on and off
> various options. There are 2 tree controls on the dialog. The tree on the
> left has fixed content - an entry for each of the 8 areas of my
> application and is populated in my OnInitDialog. The tree on the right is
> populated on demand and contains a flat list of entries relevant to any
> one section of my application. Each entry on the right hand tree has a
> checkbox. My current set of checks is defined in a 2d bool array called
> m_bColumnView. All are CTreeCtrl + CDialog derivatives.
>
> In my OnInitDialog, I populate the tree on the left and that works OK
> (there are no checkboxes). I also default the tree on the left to the
> first section, which triggers my OnTvnSelchangedTree event operation,
> which does a few basic checks, then calls my PopulateList() operation to
> populate the tree on the right, thereby giving the dialog some default
> entries. The PopulateList method creates a mask:
>
> UINT iMask = TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_PARAM;
>
> Then adds a series of tree items with checkboxes, therefore, I have a
> series of lines like this:
>
> m_treeRHS.SetCheck(m_treeRHS.InsertItem(iMask, "Name", 2, 2, NULL, NULL,
> col_name, TVI_ROOT, NULL), m_bColumnView[m_iTreeItem-1][col_name]);
>
> When I click through the sections on the left the tree on the right is
> populated by PopulateList() and behaves perfectly, but when I trigger
> PopulateList() during my OnInitDialog, the tree on the right is populated
> with all the right entries, but no checkboxes are tickes. I have stepped
> through the code and they definitely should be ticked, they just don't
> appear ticked on the screen.
>
> Any idea whats going on??
>
From: David Lowndes on
>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;
}

Alternatively, if you delay the SetCheck, by posting a user defined
message, and check the item in response to that delayed message, that
also appears to work.

Dave
From: GT on
"David Lowndes" <DavidL(a)example.invalid> wrote in message
news:s3nav55nn11r94tmu4rsffs5fe244mcund(a)4ax.com...
> >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.