It does appear as if m_htvi would be the correct value and I can get
the value of m_htvi using reflection, but it doesn't seem to work for
what I'm trying to do using the code below. Basically, I'm just trying
to hide a node checkbox.
[DllImport("coredll", CharSet=CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr hWnd, int msg,
IntPtr wParam, ref TVITEM lParam);
[DllImport("coredll.dll")]
private static extern IntPtr GetCapture();
public int TVIF_STATE = 8;
public int TVIS_STATEIMAGEMASK = 61440;
public int TV_FIRST = 4352;
public int TVM_SETITEM = 4415;
[StructLayout(LayoutKind.Sequential)] public struct TVITEM
{
public int mask;
public IntPtr hItem;
public int state;
public int stateMask;
public IntPtr pszText;
public int cchTextMax;
public int iImage;
public int iSelectedImage;
public int cChildren;
public IntPtr lParam;
}
public void HideCheckBox(System.Windows.Forms.TreeNode node)
{
//Gets the node handle
System.Reflection.FieldInfo nodeInfo =
node.GetType().GetField("m_htvi", BindingFlags.NonPublic |
BindingFlags.Instance | BindingFlags.Public);
IntPtr nodeHandle = (System.IntPtr)nodeInfo.GetValue(node);
//Gets the treeview handle
node.TreeView.Capture = true;
IntPtr treeHandle = GetCapture();
node.TreeView.Capture = false;
//Sets the desired node state
TVITEM tvi = new TVITEM();
tvi.hItem = nodeHandle;
tvi.mask = TVIF_STATE;
tvi.stateMask = TVIS_STATEIMAGEMASK;
tvi.state = 0 << 12;
SendMessage(treeHandle, TVM_SETITEM, IntPtr.Zero, ref tvi);
}