[Closed] DotNet Treeview unwanted automatic horizontal scrolling
I’m using a DotNet treeview control, and I’m having issues whenever a node is added that is longer than the width of the treeview… it automatically scrolls the treeview horizontally just enough to push the image state icons (or checkboxes, depending) off the left side of the treeview.
Is there any way to turn this off? I can’t disable scrolling because obviously the user needs to be able to scroll to get to contents that may be off the screen.
Upon further investigation, it looks like when I set the .topNode property, that’s when this happens. So in effect, that doesn’t just set the vertical scroll position, but the horizontal position as well, which isn’t what I need. I need to be able to set the vertical position without the horizontal position being effected.
Any ideas?
hi jon,
cant be sure if this is useful without trying it but the way i’d approach this is by finding out if the treenode’s string text is longer than the client rectangle width of the node itself. if so, you could abbreviate /shorten the topnode string.
Either that or shorten the topnode text anyway and store the info you need in the tag property, or a custom event arg in an inherited control.
this might help –
One thing I’d try is using the ensureVisible() method on the selected node ( treeView.selectednode.ensurevisible() ). Ensure visible will surely take care of the vertical scrolling, not sure about the horizontal.
Another thing to try would be to disable the redrawing of the treeview temporarily with beginUpdate() and endUpdate(). Not sure if that will help at all… but it’s a good practice anyway.
Marco is absolutely right. Before the adding a new node to the list call tv.beginUpdate(). And call tv.endUpdate() after the adding.
well … here is a solution:
tv.beginupdate()
tv.nodes.item[?].nodes.add <long named node>
windows.SendMessage tv.handle 0x114 6 0 -- hscroll left
tv.endupdate()
/*
-- WM_HSCROLL = 0x114
-- SB_LEFT = 6
-- SB_RIGHT = 7
windows.SendMessage tv.handle 0x114 6 0 -- hscroll left
windows.SendMessage tv.handle 0x114 7 0 -- hscroll right
*/
Thanks, everyone for your help.
Denis, your suggestion did the trick, thanks a lot!