Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

CTreeView items displaying as selected

Posted on 2000-03-08
8
Medium Priority
?
809 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 600 total points
ID: 2599633
Just change
ctlTree.SetItemState( hCurr, 0, TVIS_SELECTED );
   
to
ctlTree.SetItemState( hCurr, TVIS_SELECTED, 0xFF);

Vicky
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
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.

772 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