Solved

CTreeCtrl won't SetCheck when tree isn't visible

Posted on 2004-08-09
7
978 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
pre4 challenge 19 116
Unix Command -- Challenging  question 7 107
Authenticate using sesu from script 7 160
Problem to Office 1 68
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

710 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