Dave's Brain

Browse - Programming Tips - Why are my TreeView checkboxes working?

Date: 2010may18
OS: Windows
Language: C/C++

Q.  Why are my TreeView checkboxes working?

A.  MSDN says:

If you want to use this style, you must set the TVS_CHECKBOXES style with SetWindowLong after you create the treeview control, and before you populate the tree. Otherwise, the checkboxes might appear unchecked, depending on timing issues.
So even if you set it in .rc file that isn't enough! My practice is to never set it in the .rc file (since it only half works) and suggests that it is working. In MFC:
In win32:
void EnableCheckboxes(HWND hwndTreeView) { DWORD dwStyle = GetWindowLong(hwndTreeView, GWL_STYLE); dwStyle |= TVS_CHECKBOXES; SetWindowLong(hwndTreeView, GWL_STYLE, dwStyle); }

Add a comment

Sign in to add a comment
Copyright © 2008-2018, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.