I have very strange problem with hiding CheckBoxes in a TreeView. Everything works as it should when TreeView is on the first TabPage in the Window but when TreeView in on the second TabPage then the first TreeNode always has checkbox.
The code I'm using to hide some checkboxes looks like this:
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 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")]
public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
private void TurnOff(TreeNode node) {
TVITEM tvi = new TVITEM();
tvi.hItem = node.Handle;
tvi.mask = TVIF_STATE;
tvi.stateMask = TVIS_STATEIMAGEMASK;
tvi.state = 0;
IntPtr lparam = Marshal.AllocHGlobal(Marshal.SizeOf(tvi));
Marshal.StructureToPtr(tvi, lparam, false);
SendMessage(this.Handle, TVM_SETITEM, IntPtr.Zero, lparam);
Marshal.FreeHGlobal(lparam);
}
If someone knows solution for this problem, please share.