How to determine TreeCtrl's checked item ?

I have a TreeCtrl in Dialog box with check boxes for each of its item.
  How is it possible to determine the checked item, at runtime, when the user clicks in checkbox of that item of TreeCtrl.
  I want to determine the checked item at runtime(when user checks the checkbox) so that I can add it to ListBox simultaniously.
   How can one acheive the above?
s1a1m2erAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
ScottyDawgConnect With a Mentor Commented:
Anyway, regarding WM_LBUTTONDOWN. It does work as long as you call the base class version first - I just checked i.e.

void CTreeappView::OnLButtonDown(UINT nFlags, CPoint point)
{
      CTreeView::OnLButtonDown(nFlags, point);

    HTREEITEM hItem = GetTreeCtrl().HitTest(point);

    if (!hItem)
        return;

    bool bCheck = GetTreeCtrl().GetCheck(hItem) != 0;
}
0
 
ScottyDawgCommented:
Use the function

BOOL CTreeCtrl::GetCheck(HTREEITEM hItem ) const

to determine whether a tree item is checked or not.

Handle the TVN_SELCHANGED notification to be notified when the user has selected a new item.
0
 
s1a1m2erAuthor Commented:
TVN_SELCHANGED message occurs before the checkbox state changes.
Say,If i click on the (unchecked)checkbox of a (new)tree item,the checkbox gets checked only after,the TVN_SELCHANGED message has already occurred.So,even though the item has been selected,
GetCheck(HTREEITEM hItem )  
gives me false.
 How can i overcome the above problem?
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
ScottyDawgCommented:
Well how about WM_LBUTTONDOWN then?

Do a hit test on the treectrl at the point where the mouse button was clicked, if you get a valid HTREEITEM then call GetCheck(...)
0
 
s1a1m2erAuthor Commented:
Sorry,WM_LBUTTONDOWN occurs even before TVN_SELCHANGED.So that doesnt helps.
0
 
ScottyDawgCommented:
WM_LBUTTONUP?
0
 
s1a1m2erAuthor Commented:
ScottyDawg ,ThankYou. It was a really great help from u. I didnt know u had to call the base class first.
0
 
ScottyDawgCommented:
No problem. Glad to help.
0
 
GeorgeShiCommented:
I need to apply a similar solution but how I can capture the WM_LBUTTONDOWN message from treeview where mouse down is happened?  Thanks,
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.