Drop & Drag within a Treeview

Post

Posted
Rating:
#1 (In Topic #403)
Avatar
Expert
Quincunxian is in the usergroup ‘Expert’
 I'm trying to determine how to find the key ( or any other identifying data) when you drag and drop inside the same Treeview.

The problem is that the Drop event does not seem to be activating for the treeview ?
I've test this with some listboxes and can successfully drop and drag between them - the drop event works.
I can get the key of the treeview item that is selected to move but when releasing the mouse, there is nothing triggered.


Attached is a project to see if someone can find what I'm doing wrong with the treeview

My purpose is to be able to select a treeview item and move it to another parent or change the sequence.

Any advice appreciated.

Attachment

Treeview example code


Cheers - Quin.
I code therefore I am
Online now: Yes Back to the top

Post

Posted
Rating:
#2
Avatar
Regular
sjsepan is in the usergroup ‘Regular’
Quin,
Started to take a look at this today. In order to see what events are firing and in what sequence, I made some mods to part of the code; using the event name so my slow brain can pick out the info easier, and outputting the sequence to the Console window so I can see the history of the events:

Code (gambas)

  1. Public Sub Trv_Main_Click()
  2.  
  3.     FunctionKey = "_Click"
  4.     FromKey = Trv_Main.Current.Key
  5.     UpdateDisplay
  6.  
  7.  
  8. Public Sub Trv_Main_Drop()
  9.  
  10.     FunctionKey = "_Drop"
  11.  
  12.     UpdateDisplay
  13.  
  14.  
  15. Public Sub Trv_Main_MouseDrag()
  16.  
  17.     If Trv_Main.Current.Text <> "" Then
  18.         Fromkey = Trv_Main.Current.Key
  19.  
  20.         Trv_Main.Drag(Fromkey, "text/html")
  21.     Endif
  22.  
  23.     Trv_Main.MoveCurrent
  24.     FunctionKey = "_MouseDrag"
  25.  
  26.     UpdateDisplay
  27.  
  28.  
  29. Public Sub Trv_Main_Drag()
  30.  
  31.     FunctionKey = "_Drag"
  32.  
  33.     UpdateDisplay
  34.  
  35.  
  36. Private Sub UpdateDisplay()
  37.  
  38.     Txt_Current.text = Trv_Main.Current.Text
  39.     Txt_Item.text = Trv_Main.Item.Text
  40.     Txt_Function.text = FunctionKey
  41.  
  42.     Print Subst("Current='&1', Item='&2', Event='&3'\r\n", Trv_Main.Current.Text, Trv_Main.Item.Text, FunctionKey)
  43.  

Running the code, and dragging item20 over item19,  I see:

Current='Item20', Item='Item20', Event='_Click'

Current='Item20', Item='Home', Event='_Drag'

Current='Item20', Item='Home', Event='_Drop'

Current='Item20', Item='Item20', Event='_MouseDrag'

Examining results to see what actually occurs…

Steve
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Expert
Quincunxian is in the usergroup ‘Expert’
 Thanks Steve - let me know what you find out.
It is always possible that it's a "me and my computer" problem.

Cheers - Quin.
I code therefore I am
Online now: Yes Back to the top

Post

Posted
Rating:
#4
Avatar
Regular
sjsepan is in the usergroup ‘Regular’
Just so that I understand, you indicated initially that the Drop event did not seem to be firing, right?

The problem is that the Drop event does not seem to be activating for the treeview ?

I do see what looks like a Drop event activation, in the 3rd event in the sequence caused by dragging item20 onto item19 (see output, previous reply).
In the ListBoxes form I see that in the Drop event you are explicitly moving the item:

Code (gambas)

  1.     ListBox1.Add(Drag.data)
  2.     ListBox2.Remove(ListIndex)

However, in the main form the Drop event handler doesn't do anything explicit with the TreeView yet (Note - I previously modified the value stored in FunctionKey but the code is otherwise the same):

Code (gambas)

  1. Public Sub Trv_Main_Drop()
  2.  
  3.     FunctionKey = "_Drop"
  4.  
  5.     UpdateDisplay
  6.  

I'll admit, though, that I don't see any info in the output about the destination of the Drop (Item19 in this case). But then the listboxes example does not do so either, but places the dragged item at the end. Here, though, It seems like you would want to identify which item you hovered over, and I have not found a way to obtain than info (yet). Still looking around…
Online now: No Back to the top

Post

Posted
Rating:
#5
Avatar
Expert
Quincunxian is in the usergroup ‘Expert’
 Thanks Steve - it looks like it may be a bug that has crept in as I'm sure(?) it used to work a few gambas versions ago.
I'll post on the user email list and see what can be done.

Cheers - Quin.
I code therefore I am
Online now: Yes Back to the top

Post

Posted
Rating:
#6
Avatar
Regular
sjsepan is in the usergroup ‘Regular’
OK, never used it yet myself, and after trying, I was starting to come to the conclusion that Drag/Drop would work between controls (like you did with the listboxes), but not within one treeview control. I just could not see a way to get the destination item. Anyway, I had to admit defeat.
Hope you find out more; let us know if you get a response.
Steve S
Online now: No Back to the top

Post

Posted
Rating:
#7
Avatar
Expert
Quincunxian is in the usergroup ‘Expert’
Hi Steve,
I got a reply from the mailing list group from an Italian guy called Gianluigi.
He updated my test project code with the following and it now works.
the "Trv_Main.FindAt(Drag.X, Drag.Y)" is the key bit of code i think.

The only thing that I want to do that is different in the attached example project is maintain the original key of the item,
remove the duplicate from the original position and update the data in the database that the Treeview detail comes from.
That should be easy enough now that I understand the core process.

Code (gambas)

  1. Public Sub Trv_Main_MouseDrag()
  2.  
  3.  
  4.   With Trv_Main
  5.     If .FindAt(Mouse.X, Mouse.Y) Then Return
  6.     Drag.Icon = .Current.Picture
  7.     .Drag(.Key)
  8.  
  9.  
  10. Public Sub Trv_Main_DragMove()
  11.  
  12.   'IF Drag.Type <> Drag.Image THEN STOP EVENT
  13.  
  14.   With Trv_Main
  15.     If Not .FindAt(Drag.X, Drag.Y) Then
  16.       Drag.Show(Trv_Main, .Item.X, .Item.Y, .Item.W, .Item.H)
  17.     Else
  18.       Drag.Show(Trv_Main)
  19.     Endif
  20.  
  21.  
  22. Public Sub Trv_Main_Drop()
  23.  
  24.   Dim sKey As String
  25.  
  26.   With Trv_Main
  27.  
  28.     If Not .FindAt(Drag.X, Drag.Y) Then
  29.       sKey = .Item.Key
  30.     Endif
  31.    
  32.     Inc $iKey
  33.  
  34.     If Drag.Type = Drag.Text Then
  35.       .Add($iKey, Drag.Data,, sKey).EnsureVisible
  36.       TextBox1.Text = $iKey & ", " & sKey & ", " & Drag.Data
  37.       FunctionKey = "Drop Event"
  38.       UpdateDisplay
  39.     Endif
  40.  
  41.  
  42.  

Attachment

From - Gianluigi. V2


Cheers - Quin.
I code therefore I am
Online now: Yes Back to the top
1 guest and 0 members have just viewed this.