简体   繁体   English

TreeView关闭复选框

[英]TreeView turn off checkboxes

I have very strange problem with hiding CheckBoxes in a TreeView. 我在TreeView中隐藏CheckBox有一个非常奇怪的问题。 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. 当TreeView在窗口的第一个TabPage上时,一切正常进行,但是当TreeView在第二个TabPage上时,第一个TreeNode始终具有复选框。

没有复选框的根节点在此处输入图片说明

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. 如果有人知道解决此问题的方法,请分享。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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