简体   繁体   中英

TreeView turn off checkboxes

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM