CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    May 2002
    Location
    Jerusalem,Israel
    Posts
    174

    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 );

  2. #2
    Join Date
    Dec 2001
    Location
    New York
    Posts
    529
    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

  3. #3
    Join Date
    Nov 2003
    Location
    Bangalore
    Posts
    97

    Re:How come in my CTreeCtrl SetCheck doesn't work?

    Hi,

    Please try this link

    http://www.codeguru.com/forum/showt...eeCtrl+SetCheck

    With Regards
    Prakash
    A little progress every day.... adds upto BIG results !

  4. #4
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815

    Re: Re:How come in my CTreeCtrl SetCheck doesn't work?

    Originally posted by pgnanaprakash
    Hi,

    Please try this link

    http://www.codeguru.com/forum/showt...eeCtrl+SetCheck

    With Regards
    Prakash
    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?

  5. #5
    Join Date
    Jan 2004
    Location
    Netherlands
    Posts
    24
    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.

  6. #6
    Join Date
    Apr 2001
    Posts
    34
    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.

  7. #7
    Join Date
    Dec 2001
    Location
    New York
    Posts
    529
    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

  8. #8
    Join Date
    Jan 2004
    Location
    Netherlands
    Posts
    24
    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.

  9. #9
    Join Date
    Apr 2001
    Posts
    34
    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

  10. #10
    Join Date
    Apr 2001
    Posts
    34
    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

  11. #11
    Join Date
    Jan 2004
    Location
    Netherlands
    Posts
    24
    He thanks KeyserSoze , your solution works great. Finally my tree does exactly what I want.

  12. #12
    Join Date
    Jan 2006
    Posts
    1

    Resolved 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
  •  





Click Here to Expand Forum to Full Width

Featured