Solved

How to determine TreeCtrl's checked item ?

Posted on 2000-02-14
9
595 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 

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

Industry Leaders: 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!

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

635 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