Solved

CTreeView items displaying as selected

Posted on 2000-03-08
8
788 Views
Last Modified: 2013-11-20
Hi, I have generated an Explorer-style application in VC++ 6 and I've been working with the CTreeView in the left-side pane.

I am populating the underlying CTreeCtrl using something like:

   // ...
   CString desc = GetItemDescriptionFromElsewhere();
   treeItem.hParent = 0;
   treeItem.hInsertAfter = TVI_SORT;

   hCurr = ctlTree.InsertItem(&treeItem);
   ctlTree.SetItemText(hCurr, desc.GetBuffer(desc.GetLength()));
   ctlTree.SetItemData(hCurr, (DWORD)pSomething);
   ctlTree.SetItemState( hCurr, 0, TVIS_SELECTED );
   ctlTree.SetItemImage( hCurr, 0, 1 ); // ImageList defined elsewhere
   // ...

Am I doing this correctly? Am I missing something?

1) When the TreeView first renders, EVERYTHING appears selected (the text is highlighted although the focus box doesn't appear to be present). When I individually click on the various items, previous ones DO get de-selected (un-highlighted). This sounds like I have to individually refresh each and every item in the tree to reflect its non-selected status (I issue a GetTreeCtrl().SelectItem(NULL)) in OnInitDialog().

Is there a heuristic for doing this? None of the examples I've looked at do anything special - it just seems to behave as I want by default, although granted, they're all using (or subclassing) CTreeCtrl's directly within a dialog.

2) Is there a standard approach for explicitly setting the bitmap to display based on whether the item is expanded or not? Do I have to intercept all of the TVM_ITEMEXPANDING and TVM_ITEMEXPANDED events?

Thanks for your help.
0
Comment
Question by:ayang_ca
[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
  • 4
  • 2
  • 2
8 Comments
 
LVL 3

Expert Comment

by:SamHobbs
ID: 2599130
Are you using:

ctlTree.SetItemState(hCurr, 0,
TVIS_SELECTED);

on every item? It seems to me that if you do, then you are causing the behaviour you are describing.
0
 
LVL 3

Expert Comment

by:SamHobbs
ID: 2599147
I am sorry about my reply. I see I was wrong. The TVIS_SELECTED flag probably has no effect. Your program would work the same without it, right?



0
 
LVL 3

Accepted Solution

by:
V_Bapat earned 200 total points
ID: 2599633
Just change
ctlTree.SetItemState( hCurr, 0, TVIS_SELECTED );
   
to
ctlTree.SetItemState( hCurr, TVIS_SELECTED, 0xFF);

Vicky
0
Database Solutions Engineer FAQs

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller single-server environments.

 
LVL 3

Expert Comment

by:V_Bapat
ID: 2599650
You can also try

ctlTree.SetItemState(hCurr, ctlTree.GetItemState(hCurr, oxFF)| TVIS_SELECTED, 0xFF);

This will get the state of the currect item and OR it with TVIS_SELECTED. You supply 0xFF for statemask to indicate all states.
0
 
LVL 3

Expert Comment

by:V_Bapat
ID: 2599656
Make that 0xFFFF.
0
 
LVL 3

Expert Comment

by:V_Bapat
ID: 2599684
I wonder why you are inserting a blank item anf then setting the attributes for it. You can as well set them before inserting the item.
0
 

Author Comment

by:ayang_ca
ID: 2601327
Vikrant's suggestion was helpful but did not solve the problem.  He illustrated that I was using the state mask incorrectly and from his suggestion, I was able to verify that the selected state of each tree item was behaving as I expected (the selected bitmap would appear and disappear as I would expect.)

The problem instead, appears to be that the CTreeView is rendering the tree items from perhaps the system palette(?). However, once I manually select an item and move focus away from it, the colour gets handled properly - using the background colour of the treeview.  

So, while Vikrat hasn't solved my problems, he has helped me. I think I will try and lower the point value of this question however, because I'm still stuck.

If I can't do that, I'll create a For V_Bapat only question with a smaller point value, and create new, hopefully more refined questions for the remained.

0
 

Author Comment

by:ayang_ca
ID: 2601623
Right. Never mind. I was told I couldn't lower the point value of my question and EE went ahead and gave V_Bapat all 200 points. Oh well, congratulations!

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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 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.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

623 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