Hi Phil,
Based on my understanding, you want to exclude some checkboxes from several
treenodes in treeview.
Currently, there is not build-in support to get this done. But we can send
a TVM_SETITEM message to the treeview control, set TVITEM structure's state
field to 0, and TVITEM's hItem field to the treenode's handle. Then this
treenode will be got rid of the checkbox.
Sample code lists below:
public const int TVIF_STATE = 0x8;
public const int TVIS_STATEIMAGEMASK = 0xF000;
public const int TV_FIRST= 0x1100;
public 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")]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam,
IntPtr lParam);
private void button1_Click(object sender, System.EventArgs e)
{
TVITEM tvi=new TVITEM();
tvi.hItem=this.treeView1.SelectedNode.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.treeView1.Handle, TVM_SETITEM, IntPtr.Zero, lparam);
}
This code hides the selected treenode's checkbox and it works well on my
side. You may copy and paste in your project to have a test.
=========================================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.