I have used the accepted solution from
this question[
^] to remove
checkbox from a
treeview node in my
WM_INITDIALOG
handler.
Upon loading,
tree has a proper look. After I select the node and click on the place where
checkbox would be, nothing happens (
checkbox does not appear ) which is the correct behavior.
However, if I select the node
and press spacebar the
checkbox is automatically added to the node.
Here is the
WM_INITDIALOG
handler that illustrates the problem:
case WM_INITDIALOG:
{
HWND TreeView = GetDlgItem( hDlg, IDC_TREE1 );
DWORD dwStyle = GetWindowLong( TreeView , GWL_STYLE);
dwStyle |= TVS_CHECKBOXES;
SetWindowLongPtr( TreeView , GWL_STYLE, dwStyle );
TVINSERTSTRUCT tvis = {0};
tvis.item.mask = TVIF_TEXT;
tvis.item.pszText = L"This is root item";
tvis.hInsertAfter = TVI_LAST;
tvis.hParent = TVI_ROOT;
HTREEITEM hRootItem = reinterpret_cast<HTREEITEM>( SendMessage( TreeView ,
TVM_INSERTITEM, 0, reinterpret_cast<LPARAM>( &tvis ) ) );
TVITEM tvi;
tvi.hItem = hRootItem ;
tvi.mask = TVIF_STATE;
tvi.stateMask = TVIS_STATEIMAGEMASK;
tvi.state = 0;
TreeView_SetItem( TreeView, &tvi );
memset( &tvis, 0, sizeof(TVINSERTSTRUCT) );
tvis.item.mask = TVIF_TEXT;
tvis.item.pszText = L"This is first subitem";
tvis.hInsertAfter = TVI_LAST;
tvis.hParent = hRootItem;
HTREEITEM hNode1 = reinterpret_cast<HTREEITEM>( SendMessage( TreeView ,
TVM_INSERTITEM, 0, reinterpret_cast<LPARAM>( &tvis ) ) );
memset( &tvis, 0, sizeof(TVINSERTSTRUCT) );
tvis.item.mask = TVIF_TEXT | TVIF_STATE; tvis.item.pszText = L"This is second subitem";
tvis.hInsertAfter = TVI_LAST;
tvis.hParent = hRootItem;
HTREEITEM hNode2 = reinterpret_cast<HTREEITEM>( SendMessage( TreeView ,
TVM_INSERTITEM, 0, reinterpret_cast<LPARAM>( &tvis ) ) );
}
return (INT_PTR)TRUE;
Here is interesting quote from MSDN[
^]:
Version 5.80. Displays a check box
even if no image is associated with the item.
Perhaps this is the cause of my problem?
I ave tried handling
TVN_KEYDOWN[
^] and set items state or again removing the
checkbox but had no success.
QUESTION:
How can I properly remove
checkbox from a
tree node so it never appears again ?
Thank you.
Best regards.