Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

CTreeCtrl won't SetCheck when tree isn't visible

Posted on 2004-08-09
7
Medium Priority
?
1,010 Views
Last Modified: 2013-11-20
I'm using a CTreeCtrl in a expandable dialog(it has a more/less button to show/hide options). The dialog is contracted to start out, which means the Tree is not visible(The visible property is set to true, it is just positioned outside the visible area of the window). When initialize the dialog, i populate the tree. The items get added correctly, and I call SetCheck(item, true) and this returns true, but when I expand the dialog to see the tree, the items are all unchecked.

Also once I have the dialog open, and add items to the tree, they show up as entries but they only show up checked if the tree is visible. Does SetCheck only work if the tree is visible or do I need to do something different.

Here's some code
                  POSITION p;
                  CTreeCtrl *rl = (CTreeCtrl*)GetDlgItem( IDC_TREE );
                  for(int i=0;i<m_list.GetCount();i++)
                  {
                        p = m_list.FindIndex(i);
                        if(p)
                        {
                              rImage img = m_list.GetAt(p);
                              HTREEITEM item = rl->InsertItem(img.name.c_str());
                              BOOL res = rl->SetCheck(item, img.checked);
                        }
                  }
0
Comment
Question by:tcf22
[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
7 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11755583
Have you tried with a fixed image? I am suspecting the problem is with the data pointed by p, and not with your control.
0
 

Author Comment

by:tcf22
ID: 11756346
What do you mean by "with a fixed image"?

p isn't the issue, it is just the POSITION of a struct in a CList.
These command get executed
                         HTREEITEM item = rl->InsertItem(img.name.c_str());
                         BOOL res = rl->SetCheck(item, img.checked);

The string (img.name.c_str()) is always added to the tree and the variable res always comes back true but the item that is added is unchecked reagardless of the value of img.checked.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 11759927
try GetDlgItem( IDC_TREE )->Invalidate(); after the resizing, it could be a painting problem
0
 

Accepted Solution

by:
CetusMOD earned 0 total points
ID: 12170521
PAQed - no points refunded (of 250)

CetusMOD
Community Support Moderator
0
 

Expert Comment

by:tonyblues
ID: 13389260
One solution is to call ModifyStyle to remove TVS_CHECKBOXES and then call ModifyStyle again to add TVS_CHECKBOXES back, before you call SetCheck. That is (in your sample):

CTreeCtrl *rl = (CTreeCtrl*)GetDlgItem( IDC_TREE );
rl->ModifyStyle(TVS_CHECKBOXES, 0);  // remove TVS_CHECKBOXES style
rl->ModifyStyle(0, TVS_CHECKBOXES);  // add TVS_CHECKBOXES style back
for(int i=0;i<m_list.GetCount();i++)
...


It really works. But I don't know why. It's just so strange!
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

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 …
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

730 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