Solved

CTreeCtrl won't SetCheck when tree isn't visible

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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 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.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

706 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

17 Experts available now in Live!

Get 1:1 Help Now