Dave's Brain

Browse - programming tips - win32 hide treeview checkbox

Date: 2010may17
OS: Windows

Language: C/C++	

Keywords: grey, gray, disable

Q.  How can I hide a checkbox in a TreeView ?

A.  Here's a function that hides it.  Until a user clicks on it.
You need to add more code to prevent it from re-appear when the user
clicks on it.

	BOOL SetCheckStateDisabled(HWND hwndTree, HTREEITEM hItem, const BOOL bChecked)
	{
		TVITEM		tvItem;

		ZeroMemory(&tvItem, sizeof(tvItem));

		tvItem.mask = TVIF_HANDLE | TVIF_STATE;
		tvItem.hItem = hItem;
		tvItem.stateMask = TVIS_STATEIMAGEMASK;

		// Image 3 in the tree-view check box image list is the
		// disabled unchecked box. Image 4 is the disabled checked box.

		tvItem.state = INDEXTOSTATEIMAGEMASK((bChecked ? 4 : 3));

		return TreeView_SetItem(hwndTree, &tvItem);
	}
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2010, 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.