Automatically scroll to end of treeview?

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Automatically scroll to end of treeview?

Riccardo
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?

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...
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Automatically scroll to end of treeview?

Tobias Boege-2
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

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Automatically scroll to end of treeview?

Riccardo
Thank very much Tobias, for the valuable advice.

Because I know what I'm adding it simply worked to apply your recommended approach immediately after adding the new node without the loop or the condition:

   trvLog.Add(trvLog.Count, logtext)
   trvLog.Item.EnsureVisible

And also the caveat about the TreeView is timely...I'll find a different approach.

cheers.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Automatically scroll to end of treeview?

Gianluigi
Maybe this topic could help [0]

Regards
Gianluigi

[0]
http://gambas.8142.n7.nabble.com/Accessing-the-Treeview-Collection-td20313.html#a20317


2017-03-22 11:27 GMT+01:00 Riccardo <[hidden email]>:

> Thank very much Tobias, for the valuable advice.
>
> Because I know what I'm adding it simply worked to apply your recommended
> approach immediately after adding the new node without the loop or the
> condition:
>
>    trvLog.Add(trvLog.Count, logtext)
>    trvLog.Item.EnsureVisible
>
> And also the caveat about the TreeView is timely...I'll find a different
> approach.
>
> cheers.
>
>
>
> --
> View this message in context: http://gambas.8142.n7.nabble.
> com/Automatically-scroll-to-end-of-treeview-tp58666p58669.html
> Sent from the gambas-user mailing list archive at Nabble.com.
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Gambas-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Automatically scroll to end of treeview?

Tobias Boege-2
On Wed, 22 Mar 2017, Gianluigi wrote:
> Maybe this topic could help [0]
>
> Regards
> Gianluigi
>
> [0]
> http://gambas.8142.n7.nabble.com/Accessing-the-Treeview-Collection-td20313.html#a20317
>

This looks to me like they were trying to list all keys used by a TreeView.
That task can be accomplished by your favourite flavour of tree traversal
algorithm, in particular Depth-first search, which is easy to implement
recursively, *without* a forest of GOTOs and labels.

The current implementation of TreeView internally has a Collection of all
the items, which could be used to enumerate all used keys -- but it is not
exposed through the TreeView interface. So the only way I see to enumerate
keys is to traverse the tree structure by using TreeView.Move*() methods.

But even if you could enumerate all the keys in the TreeView, it wouldn't
be relevant at all to scrolling the TreeView or Drag&Drop, wouldn't it?

Regards,
Tobi

--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Automatically scroll to end of treeview?

Gianluigi
Hello Tobias,
unfortunately I was not able to do better than Wally,
I tried but I did not move from here :-(
See attached
I'm afraid did not understand the original question.

Regards
Gianluigi

2017-03-22 14:30 GMT+01:00 Tobias Boege <[hidden email]>:

> On Wed, 22 Mar 2017, Gianluigi wrote:
> > Maybe this topic could help [0]
> >
> > Regards
> > Gianluigi
> >
> > [0]
> > http://gambas.8142.n7.nabble.com/Accessing-the-Treeview-
> Collection-td20313.html#a20317
> >
>
> This looks to me like they were trying to list all keys used by a TreeView.
> That task can be accomplished by your favourite flavour of tree traversal
> algorithm, in particular Depth-first search, which is easy to implement
> recursively, *without* a forest of GOTOs and labels.
>
> The current implementation of TreeView internally has a Collection of all
> the items, which could be used to enumerate all used keys -- but it is not
> exposed through the TreeView interface. So the only way I see to enumerate
> keys is to traverse the tree structure by using TreeView.Move*() methods.
>
> But even if you could enumerate all the keys in the TreeView, it wouldn't
> be relevant at all to scrolling the TreeView or Drag&Drop, wouldn't it?
>
> Regards,
> Tobi
>
> --
> "There's an old saying: Don't change anything... ever!" -- Mr. Monk
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Gambas-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user

TestOnTreeView-0.0.1.tar.gz (16K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Traversing a TreeView (was: Automatically scroll to end of treeview?)

Tobias Boege-2
On Wed, 22 Mar 2017, Gianluigi wrote:
> Hello Tobias,
> unfortunately I was not able to do better than Wally,
> I tried but I did not move from here :-(
> See attached
> I'm afraid did not understand the original question.
>

An implementation of what I was talking about is attached.

Regards,
Tobi

--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user

TestOnTreeView-0.0.2.tar.gz (16K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Traversing a TreeView (was: Automatically scroll to end of treeview?)

Gianluigi
Dear Tobias,

you were born teacher. 👍
Thank you very much for the example and explanations.

Regards
Gianluigi

2017-03-22 19:38 GMT+01:00 Tobias Boege <[hidden email]>:

> On Wed, 22 Mar 2017, Gianluigi wrote:
> > Hello Tobias,
> > unfortunately I was not able to do better than Wally,
> > I tried but I did not move from here :-(
> > See attached
> > I'm afraid did not understand the original question.
> >
>
> An implementation of what I was talking about is attached.
>
> Regards,
> Tobi
>
> --
> "There's an old saying: Don't change anything... ever!" -- Mr. Monk
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Gambas-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Loading...