|
-
July 4th, 2002, 07:13 AM
#1
How come in my CTreeCtrl SetCheck doesn't work?
When I am populating my CTreectrl with nodes (which is done from the MyCFormView::OnInitialUpdate()) - right after I do InsertItem - I then do SetCheck - yet this doesn't show the item checked when the application goes up. Note that right after a SetCheck I do a GetCheck to see that it was checked and it shows that it is. Does anyone know why??
HTREEITEM moduleItem=m_TreeCtrl->InsertItem(&insertStr);
m_TreeCtrl->SetCheck(moduleItem,TRUE );
-
July 4th, 2002, 09:10 AM
#2
hmm...
m_TreeCtrl.SetCheck(hItem,TRUE);
that should work. how do you set your checkboxes for your treectrl?
did you draw your own?
if so try it
Code:
m_TreeCtrl.SetItemState(
hItem// item
,INDEXTOSTATEIMAGEMASK(UNCHECK),//UNCHECK here is 1, the image index. 2 for check, hey that's depend on your BMP image
TVIS_STATEIMAGEMASK // saying you want to change state image to treectrl, there is another image, normal image, you dont' want to change that.
);
good luck
BP
-
January 8th, 2004, 02:48 AM
#3
Re:How come in my CTreeCtrl SetCheck doesn't work?
A little progress every day.... adds upto BIG results !
-
January 8th, 2004, 03:11 AM
#4
Re: Re:How come in my CTreeCtrl SetCheck doesn't work?
What's the point in bringing up all those old posts with the same question and giving a reference to the same thread (with a link which doesn't work, BTW) five times in a row?
-
January 15th, 2004, 07:48 AM
#5
Does anybody know a solution for the above problem. The frustrating part is that in some cases the checkboxes are actually checked but most of time not. And I do exactly the same (I made a function to check all the tree items). Is this a bug, or is there just something I forgot.
-
January 16th, 2004, 07:17 PM
#6
I am currently having the same problem.
I'm setting them to true in the OnInitDialog() of my PropertyPage.
If I call GetCheck() immediately after, I get the correct result, but the checks are not drawn.
I'm simply using the TVS_CHECKBOXES style, and SetCheck(). No funny business. I've done it a gazillion times before without hickups...
Most curious.
I'm running XP, Visual Studio 6.
Last edited by KeyserSoze; January 16th, 2004 at 07:54 PM.
-
January 17th, 2004, 09:26 PM
#7
really... i never have any problem..
did you forget to update the dialog?
sometime i dont' forget to call UpdateData() and wondering why all those data didn't get change eventhough I code were right.
So check if you have called UpdataData() first.
BP
-
January 19th, 2004, 02:55 AM
#8
I must admit that I never used updateData(), but somehow all my tree items get added just fine. The only problem is the getCheck() operation. I tried adding updateData() but unfortunately that does not work either. In the OnInitDialog() function from my dialog that contains my tree I call the following (simplified) function:
Code:
void CGroups::updateTree(CMyTreeCtrl *a_tree)
{
a_tree->DeleteAllItems();
std::map<int,CGroup>::iterator g_pos = this->m_groups.begin();
while (g_pos != this->m_groups.end())
{
HTREEITEM hGroup = a_tree->InsertItem(g_pos->second.text);
a_tree->SetCheck(hGroup,g_pos->second.visible);
g_pos++;
}
a_tree->UpdateData();
}
The real function is somewhat more complex with more loops for deeper levels of the tree but I use the same method for setting the checkbox. I also have a function that manually updates all the checkboxes from an administration, and the funny thing is that it only works when I call that function from the tree function OnNMClick. I tried calling that same function from different places but then it does not work.
-
January 20th, 2004, 02:40 PM
#9
Mza,
Have you figured this out yet? I'm doing almost exactly what you're doing, and am having the same issue.
I've tried UpdateData(TRUE/FALSE), RedrawWindow(), Invalidate(), etc. etc. still no luck.
I've since moved on to other tasks and figured I'd come back to this.
Have you had any luck in the past few days?
Regards,
Morgan
-
January 20th, 2004, 03:15 PM
#10
Ok, I've figured out how to get this to work.
In my OnInitDialog(), just before calling my routine that populates and checks the tree ctrl, I added:
Code:
//remove and add the checkbox style.
m_ctrlTree.ModifyStyle( TVS_CHECKBOXES, 0 );
m_ctrlTree.ModifyStyle( 0, TVS_CHECKBOXES );
That did it for me. Apparantly it's not enough to have the style specified in your resource file.
Hope this helps others who are frustrated by this
-
January 21st, 2004, 02:36 AM
#11
He thanks KeyserSoze , your solution works great. Finally my tree does exactly what I want.
-
January 3rd, 2006, 04:29 AM
#12
Re: How come in my CTreeCtrl SetCheck doesn't work?
The most strange problem is solved with the most strange solution.
Thanks, it works great for me
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|