Automatic tree sorting after crash

Hi,

I am looking for a way to set the width of a tree for the maximum or maximum size of the longest treenode in it when a node is reset or opened.

I tried using clientize .. but this does not work. Is there any other way to check which node is the longest and set TreeView.Width to this size?

+3
source share
1 answer

After some searching on the net, I found this method:

private const int GWL_STYLE = -16;
private const int WS_VSCROLL = 0x00200000;
private const int WS_HSCROLL = 0x00100000;


[DllImport("user32.dll", ExactSpelling = false, CharSet = CharSet.Auto)]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);

and

//tree = instance of a treeview
tree.AfterExpand += (s, ea) =>
{
    int style = GetWindowLong(tree.Handle, GWL_STYLE);
    while ((style & WS_HSCROLL) != 0)
    {
        tree.Width++;
        style = GetWindowLong(tree.Handle, GWL_STYLE);
    }
};

Of course, you can use this on the button!

+1
source

All Articles