public void UpdateCheckboxVisibility(MultiSelectTreeNode treeNode) { if (CheckBoxes && treeNode.Handle != IntPtr.Zero && Handle != IntPtr.Zero) { NativeMethods.TVITEM tvItem = new NativeMethods.TVITEM(); tvItem.hItem = treeNode.Handle; tvItem.mask = NativeMethods.TVIF_STATE; tvItem.stateMask = NativeMethods.TVIS_STATEIMAGEMASK; tvItem.state = 0; if (treeNode.ShowCheckBox && treeNode.Checked) { tvItem.state = 2 << 12; } else if (treeNode.ShowCheckBox) { tvItem.state = 1 << 12; } IntPtr lparam = Marshal.AllocHGlobal(Marshal.SizeOf(tvItem)); Marshal.StructureToPtr(tvItem, lparam, false); Win32.SendMessage(Handle, NativeMethods.TVM_SETITEM, IntPtr.Zero, lparam); } }