Skip to content

Instantly share code, notes, and snippets.

@vereperrot
Created December 1, 2015 10:08
Show Gist options
  • Save vereperrot/dca0bb32599c26f07d7c to your computer and use it in GitHub Desktop.
Save vereperrot/dca0bb32599c26f07d7c to your computer and use it in GitHub Desktop.
using System.Runtime.InteropServices
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)
{
this.treeView1.SelectedNode=this.treeView1.Nodes[0];
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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment