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