Solved

How to determine TreeCtrl's checked item ?

Posted on 2000-02-14
9
559 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Macro to save highlighted rows as a separate file 5 43
ffmpeg - "rtsp://...... Operation not permitted" 4 81
sum13 challenge 24 107
matchUp  challenge 9 110
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: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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.

809 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