Solved

CTreeView items displaying as selected

Posted on 2000-03-08
8
723 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
Comment Utility
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
Comment Utility
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
Comment Utility
Just change
ctlTree.SetItemState( hCurr, 0, TVIS_SELECTED );
   
to
ctlTree.SetItemState( hCurr, TVIS_SELECTED, 0xFF);

Vicky
0
 
LVL 3

Expert Comment

by:V_Bapat
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 3

Expert Comment

by:V_Bapat
Comment Utility
Make that 0xFFFF.
0
 
LVL 3

Expert Comment

by:V_Bapat
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Need to retreive data from .TFS file exported by DVR 8 166
Define unique primary key 9 81
either24  challenge 19 83
Fibonacci challenge 11 81
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…
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now