HighTechTalks DotNet Forums  

Treeview with Checkboxes in root nodes only

Dotnet Framework (WinForms Controls) microsoft.public.dotnet.framework.windowsforms.controls


Discuss Treeview with Checkboxes in root nodes only in the Dotnet Framework (WinForms Controls) forum.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Don
 
Posts: n/a

Default Treeview with Checkboxes in root nodes only - 05-28-2007 , 06:52 AM






Is it possible to set a Treeview control to show checkboxes on root
nodes only?

- Don



Reply With Quote
  #2  
Old   
Morten Wennevik [C# MVP]
 
Posts: n/a

Default Re: Treeview with Checkboxes in root nodes only - 05-28-2007 , 08:48 AM






On Mon, 28 May 2007 13:52:52 +0200, Don <unknown (AT) oblivion (DOT) .com> wrote:

Quote:
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]


Reply With Quote
  #3  
Old   
G Himangi
 
Posts: n/a

Default Re: Treeview with Checkboxes in root nodes only - 05-29-2007 , 10:34 PM



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
---------


"Don" <unknown (AT) oblivion (DOT) .com> wrote

Quote:
Is it possible to set a Treeview control to show checkboxes on root nodes
only?

- Don



Reply With Quote
  #4  
Old   
.Net Follower .Net Follower
 
Posts: n/a

Default Re: Treeview with Checkboxes in root nodes only - 05-19-2011 , 10:29 AM



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.

Quote:
On Monday, May 28, 2007 7:52 AM Don wrote:

Is it possible to set a Treeview control to show checkboxes on root
nodes only?

- Don

Quote:
On Monday, May 28, 2007 9:48 AM Morten Wennevik [C# MVP] wrote:

On Mon, 28 May 2007 13:52:52 +0200, Don <unknown (AT) oblivion (DOT) .com> wrote:


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]

Quote:
On Tuesday, May 29, 2007 11:34 PM G Himangi wrote:

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
---------


"Don" <unknown (AT) oblivion (DOT) .com> wrote in message
newsoz6i.230537$DE1.219909 (AT) pd7urf2no (DOT) ..

Quote:
On Friday, June 18, 2010 1:39 PM b hamric wrote:

Usage:

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);

}

}



I took this guys code and made it a static class:

http://www.craigmurphy.com/blog/?p=262

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.