Solved

CTreeView items displaying as selected

Posted on 2000-03-08
8
751 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
  • 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASCII Non-Printable characters/codes and their HTML equivalents 6 115
dog bark java program 15 95
java ^ examples 8 66
noX challenge 17 117
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.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

777 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