Solved

How to determine TreeCtrl's checked item ?

Posted on 2000-02-14
9
577 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:s1a1m2er
ID: 2521981
Sorry,WM_LBUTTONDOWN occurs even before TVN_SELCHANGED.So that doesnt helps.
0
 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Question regarding Copy/Paste 16 97
abstract class with all non abstract mentods 6 84
FizzBuzz challenge 9 83
unix example issues 18 106
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

679 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