Solved

CTreeCtrl won't SetCheck when tree isn't visible

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Expand macro to include alternate header placement and naming 5 71
sum13 challenge 24 107
wordmultiple challenge 12 131
Not needed 13 110
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…
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.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

776 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