Discussion:
Treeview with Checkboxes in root nodes only
(too old to reply)
Don
2007-05-28 11:52:52 UTC
Permalink
Is it possible to set a Treeview control to show checkboxes on root
nodes only?

- Don
Morten Wennevik [C# MVP]
2007-05-28 13:48:09 UTC
Permalink
Post by Don
Is it possible to set a Treeview control to show checkboxes on root
nodes only?
- Don
Hi Don,

Short of ownerdrawing the entire tree I fear not. Setting DrawMode to TreeViewDrawMode.OwnerDrawAll you can handle all the drawing yourself and just not draw the checkbox for anything but the parent. However, you also need to draw the + and - signs, any help lines and indentations.
--
Happy coding!
Morten Wennevik [C# MVP]
G Himangi
2007-05-30 03:34:58 UTC
Permalink
It is possible if you interact with the TreeView using Win32 treeview
messages TVM_*. You will need to change the 'state' of each node (see TVITEM
structure in Platform SDK).

---------
- G Himangi, Sky Software http://www.ssware.com
Shell MegaPack : GUI Controls For Drop-In Windows Explorer like Shell
Browsing Functionality For Your App (.Net & ActiveX Editions).
EZNamespaceExtensions.Net : Develop namespace extensions rapidly in .Net
EZShellExtensions.Net : Develop all shell extensions,explorer bars and BHOs
rapidly in .Net
---------
Is it possible to set a Treeview control to show checkboxes on root nodes
only?
- Don
.Net Follower .Net Follower
2011-05-19 15:29:26 UTC
Permalink
Hello!
I've created the descendants of TreeView-control and TreeNode, those allow to hide checkboxes of individual nodes. You can find it here http://dotnetfollower.com/wordpress/2011/05/winforms-treeview-hide-checkbox-of-treenode/.
Just use special class of node to hide its checkbox.
Post by Don
Is it possible to set a Treeview control to show checkboxes on root
nodes only?
- Don
Post by Morten Wennevik [C# MVP]
Hi Don,
Short of ownerdrawing the entire tree I fear not. Setting DrawMode to TreeViewDrawMode.OwnerDrawAll you can handle all the drawing yourself and just not draw the checkbox for anything but the parent. However, you also need to draw the + and - signs, any help lines and indentations.
--
Happy coding!
Morten Wennevik [C# MVP]
Post by G Himangi
It is possible if you interact with the TreeView using Win32 treeview
messages TVM_*. You will need to change the 'state' of each node (see TVITEM
structure in Platform SDK).
---------
- G Himangi, Sky Software http://www.ssware.com
Shell MegaPack : GUI Controls For Drop-In Windows Explorer like Shell
Browsing Functionality For Your App (.Net & ActiveX Editions).
EZNamespaceExtensions.Net : Develop namespace extensions rapidly in .Net
EZShellExtensions.Net : Develop all shell extensions,explorer bars and BHOs
rapidly in .Net
---------
TreeViewHelper.hideCheck(treeView1, currentNode);
TreeViewHelper.cs
using System;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace SetupRevision
{
static class TreeViewHelper
{
private const int TVIF_STATE = 0x8;
private const int TVIS_STATEIMAGEMASK = 0xF000;
private const int TV_FIRST = 0x1100;
private const int TVM_SETITEM = TV_FIRST + 63;
public static void hideCheck(TreeView treeView, TreeNode node)
{
TVITEM tvItem = new TVITEM();
tvItem.hItem = node.Handle;
tvItem.mask = TVIF_STATE;
tvItem.stateMask = TVIS_STATEIMAGEMASK;
tvItem.state = 0;
IntPtr lparam = Marshal.AllocHGlobal(Marshal.SizeOf(tvItem));
Marshal.StructureToPtr(tvItem, lparam, false);
SendMessage(treeView.Handle, TVM_SETITEM, IntPtr.Zero, lparam);
}
private struct TVITEM
{
public int mask;
public IntPtr hItem;
public int state;
public int stateMask;
[MarshalAs(UnmanagedType.LPTStr)]
public String lpszText;
public int cchTextMax;
public int iImage;
public int iSelectedImage;
public int cChildren;
public IntPtr lParam;
}
[DllImport("user32.dll")]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
}
}
http://www.craigmurphy.com/blog/?p=262
Loading...