简体   繁体   中英

How to do vertical and horizontal scrolling in treeview?

I have a treeview with a fixed size. How can i make it scrollable to horizontal and vertical? When i set Scrollable to true, it adds only vertical scroll and when scroll reach the bottom of the form and there is text remaining the scroll didn't go down.Help me please.

ps sorry for poor english

You can try this approach

private const int WM_SCROLL = 276; // Horizontal scroll
private const int WM_VSCROLL = 277; // Vertical scroll
private const int SB_LINEUP = 0; // Scrolls one line up
private const int SB_LINELEFT = 0;// Scrolls one cell left
private const int SB_LINEDOWN = 1; // Scrolls one line down
private const int SB_LINERIGHT = 1;// Scrolls one cell right
private const int SB_PAGEUP = 2; // Scrolls one page up
private const int SB_PAGELEFT = 2;// Scrolls one page left
private const int SB_PAGEDOWN = 3; // Scrolls one page down
private const int SB_PAGERIGTH = 3; // Scrolls one page right
private const int SB_PAGETOP = 6; // Scrolls to the upper left
private const int SB_LEFT = 6; // Scrolls to the left
private const int SB_PAGEBOTTOM = 7; // Scrolls to the upper right
private const int SB_RIGHT = 7; // Scrolls to the right
private const int SB_ENDSCROLL = 8; // Ends scroll

[DllImport("user32.dll",CharSet=CharSet.Auto)]
private static extern int SendMessage(IntPtr hWnd, int wMsg,IntPtr wParam, IntPtr lParam);

SendMessage(treeView.Handle, WM Scroll Message, (IntPtr) Scroll Command ,IntPtr.Zero);

Scroll page up

SendMessage(treeView.Handle, WM_VSCROLL,(IntPtr)SB_PAGEUP,IntPtr.Zero);

Scroll page down

 SendMessage(treeView.Handle, WM_VSCROLL,(IntPtr)SB_PAGEDOWN,IntPtr.Zero);

What ended up working for me was fixing up [keyboardP]'s code snippet:

myTreeView.Nodes[myTreeView.Nodes.Count - 1].EnsureVisible();

presto. horizontal bar.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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