Solved

How to determine TreeCtrl's checked item ?

Posted on 2000-02-14
9
548 Views
Last Modified: 2013-11-20
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?
0
Comment
Question by:s1a1m2er
  • 5
  • 3
9 Comments
 
LVL 1

Expert Comment

by:ScottyDawg
ID: 2521780
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
 

Author Comment

by:s1a1m2er
ID: 2521886
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
 
LVL 1

Expert Comment

by:ScottyDawg
ID: 2521931
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
 

Author Comment

by:s1a1m2er
ID: 2521981
Sorry,WM_LBUTTONDOWN occurs even before TVN_SELCHANGED.So that doesnt helps.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Expert Comment

by:ScottyDawg
ID: 2521991
WM_LBUTTONUP?
0
 
LVL 1

Accepted Solution

by:
ScottyDawg earned 40 total points
ID: 2522014
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
 

Author Comment

by:s1a1m2er
ID: 2522230
ScottyDawg ,ThankYou. It was a really great help from u. I didnt know u had to call the base class first.
0
 
LVL 1

Expert Comment

by:ScottyDawg
ID: 2522253
No problem. Glad to help.
0
 

Expert Comment

by:GeorgeShi
ID: 14764392
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
maxBlock challenge 30 112
conditional code and condition difference 9 77
fizzArray  challenge 1 63
modThree challenge 4 79
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now