[Gambas-user] Automatically scroll to end of treeview?
Tobias Boege
taboege at ...626...
Wed Mar 22 11:16:10 CET 2017
On Wed, 22 Mar 2017, Riccardo wrote:
> How do I automatically scroll to the end of a TreeView when a new node is
> added?
>
> I've tried /trvLog.MoveLast/ but that doesn't work?
>
TreeView.MoveLast() only sets the internal cursor to the last element.
The documentation is very unclear here. According to the source code
(gb.gui.base), "last element" means "last child of the TreeView root".
So this is not what you want. You want the lowest visible element.
Also setting the internal cursor only will not affect the GUI (because
it's called the *internal* cursor). Thus once you arrive at the lowest
element, you have to call TreeView.Item.EnsureVisible().
I don't know of any better method than this loop to get you there:
' Take a shortcut to the last child of the root, which saves some
' MoveBelow() calls
If hTreeView.MoveLast() Then Return ' your tree is empty
Do
' Empty body! Everything is done in the Until condition
Loop Until hTreeView.MoveBelow() ' move to lowest *visible* element
hTreeView.MoveBack()
hTreeView.Item.EnsureVisible()
> Also, can I make the Drag.Move setting apply to a node (record) in a
> TreeView. That is, if I drag a record in a TreeView to another location
> within the same control, can I have the drag action automatically move the
> original record? Setting trvLog.Action = Drag.Move doesn't work...
>
I can't help you here. TreeView apparently doesn't support Drag&Drop by
itself, so setting any Drag properties won't accomplish anything, and
I myself failed at least twice already to implement a TreeView with
draggable entries (using Item.Reparent()). My code seems to work at the
beginning but after enough drags, the TreeView control crashes reliably.
I haven't gotten around to submit a bug report yet.
Regards,
Tobi
--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
More information about the User
mailing list