1

Topic: The strange behavior CTreeViewCtrl and SetCheckState

VS2008, 2010. There is a primitive WTL-dialogue with a tree on it. At a tree it is included properties "to show the check-boksy". class CMainDlg: public CDialogImpl <CMainDlg> {public: enum {IDD = IDD_MAINDLG};//a miscellaneous....//...... HTREEITEM htiRoot;}; at initialization I do so: LRESULT CMainDlg:: OnInitDialog (UINT/*uMsg*/, WPARAM/*wParam*/, LPARAM/*lParam*/, BOOL&/*bHandled*/) {WTL:: CTreeViewCtrl tree; tree. Attach (GetDlgItem (IDC_TREE1)); htiRoot = tree. InsertItem (L "All Items", TVI_ROOT, TVI_LAST);//I add still  tree. Expand (htiRoot); tree. SetCheckState (htiRoot, TRUE); tree. Detach (); return TRUE;} On idea, it should be selected root . It does not happen. And here if to postpone flag setting for some milliseconds, for example, to make so: LRESULT CMainDlg:: OnInitDialog (UINT/*uMsg*/, WPARAM/*wParam*/, LPARAM/*lParam*/, BOOL&/*bHandled*/) {WTL:: CTreeViewCtrl tree; tree. Attach (GetDlgItem (IDC_TREE1)); htiRoot = tree. InsertItem (L "All Items", TVI_ROOT, TVI_LAST); tree. Detach ();//we set alarm clock SetTimer (99, 250); return TRUE;} LRESULT CMainDlg:: OnTimer (UINT/*uMsg*/, WPARAM wParam, LPARAM/*lParam*/, BOOL&/*bHandled*/) {if (wParam! = 99) return 0; KillTimer (99); WTL:: CTreeViewCtrl tree; tree. Attach (GetDlgItem (IDC_TREE1)); tree. SetCheckState (htiRoot, TRUE); tree. Detach (); return 0;} that  is selected. Why  it is not selected from OnInitDialog?

2

Re: The strange behavior CTreeViewCtrl and SetCheckState

The most interesting if to make GetCheckState, we receive different results: LRESULT CMainDlg:: OnInitDialog (UINT/*uMsg*/, WPARAM/*wParam*/, LPARAM/*lParam*/, BOOL&/*bHandled*/) {WTL:: CTreeViewCtrl tree; tree. Attach (GetDlgItem (IDC_TREE1)); htiRoot = tree. InsertItem (L "All Items", TVI_ROOT, TVI_LAST);//I add still  tree. Expand (htiRoot); tree. SetCheckState (htiRoot, TRUE);//it is checked, we receive bb = TRUE BOOL bb = tree. GetCheckState (htiRoot); TRACE (L "CheckState = %i", int (bb)); tree. Detach (); return TRUE;} LRESULT CMainDlg:: OnBnClickedButton2 (WORD/*wNotifyCode*/, WORD/*wID*/, HWND/*hWndCtl*/, BOOL&/*bHandled*/) {WTL:: CTreeViewCtrl tree; tree. Attach (GetDlgItem (IDC_TREE1));//it is checked, we receive bb = FALSE BOOL bb = tree. GetCheckState (htiRoot); TRACE (L "CheckState = %i", int (bb)); tree. Detach (); return 0;} In OnInitDialog it is had bb = TRUE, and then, pushing the button, we receive bb = FALSE. I.e. the state all the same is installed, and then dropped.

3

Re: The strange behavior CTreeViewCtrl and SetCheckState

Hello, ZealPack, you wrote: ZP> VS2008, 2010. In MSDN in article about styles for TVS_CHECKBOXES there is phrase 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. Any timing issues... It is possible  TVN_ITEMCHANGED and to look, who and when changes an item state (drops check).

4

Re: The strange behavior CTreeViewCtrl and SetCheckState

Style TVS_CHECKBOXES costs. But on  the case made once again SetWindowLong, before populate - one horse-radish, did not help. Apparently, these timing issues also influence that they start to be filled through 200.