Solved

CTreeView items displaying as selected

Posted on 2000-03-08
8
771 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
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!

 
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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
not able to insert into temp table 68 174
Expand macro to ask for filename column 8 37
unable to delete all specified values regedit 38 728
post4 challenge 28 113
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seveā€¦
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.

733 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