CheckBoxes In TreeView

J

Jalal Akram

I want to implement checkboxes in all child in a treeview EXCEPT all top
most root nodes.

TreeView control's CheckBoxes property implement this functionality to all
nodes.
So is there some way to implement CheckBox to some specific node?

Thanks
 
C

Claes Bergefall

You can remove the checkbox for a specific node by setting its
state image index to 0. You can use the following to do that:

Imports System.Runtime.InteropServices

Public Const TVIF_STATE As Integer = &H8
Public Const TVIS_STATEIMAGEMASK As Integer = &HF000
Public Const TV_FIRST As Integer = &H1100
Public Const TVM_SETITEM As Integer = TV_FIRST + 63

<StructLayout(LayoutKind.Sequential)> Public Structure TVITEM
Public mask As Integer
Public hItem As IntPtr
Public state As Integer
Public stateMask As Integer
<MarshalAs(UnmanagedType.LPTStr)> Public lpszText As String
Public cchTextMax As Integer
Public iImage As Integer
Public iSelectedImage As Integer
Public cChildren As Integer
Public lParam As IntPtr
End Structure

Public Overloads Declare Auto Function SendMessage Lib "User32.dll" (ByVal
hwnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByRef lParam
As TVITEM) As Integer

Public Sub TreeNode_SetStateImageIndex(ByVal node As TreeNode, ByVal index
As Integer)
Dim tvi As TVITEM
tvi.hItem = node.Handle
tvi.mask = TVIF_STATE
tvi.stateMask = TVIS_STATEIMAGEMASK
tvi.state = index << 12
SendMessage(node.TreeView.Handle, TVM_SETITEM, IntPtr.Zero, tvi)
End Sub

To clear all root nodes simply do this:

For Each node as TreeNode In myTreeView.Nodes
TreeNode_SetStateImageIndex(node, 0)
Next


/claes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top