Drop & Drag within a Treeview
Posted
#1
(In Topic #403)
Expert

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.
Treeview example code
Cheers - Quin.
I code therefore I am
I code therefore I am
Posted
Regular

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)
- FunctionKey = "_Click"
- UpdateDisplay
- FunctionKey = "_Drop"
- UpdateDisplay
- Trv_Main.Drag(Fromkey, "text/html")
- Trv_Main.MoveCurrent
- FunctionKey = "_MouseDrag"
- UpdateDisplay
- FunctionKey = "_Drag"
- UpdateDisplay
- Txt_Current.text = Trv_Main.Current.Text
- Txt_Item.text = Trv_Main.Item.Text
- Txt_Function.text = FunctionKey
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
Posted
Expert

It is always possible that it's a "me and my computer" problem.
Cheers - Quin.
I code therefore I am
I code therefore I am
Posted
Regular

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)
- ListBox1.Add(Drag.data)
- 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):
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…
Posted
Expert

I'll post on the user email list and see what can be done.
Cheers - Quin.
I code therefore I am
I code therefore I am
Posted
Regular

Hope you find out more; let us know if you get a response.
Steve S
Posted
Expert

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)
- With Trv_Main
- 'IF Drag.Type <> Drag.Image THEN STOP EVENT
- With Trv_Main
- Drag.Show(Trv_Main, .Item.X, .Item.Y, .Item.W, .Item.H)
- Drag.Show(Trv_Main)
- With Trv_Main
- Inc $iKey
- .Add($iKey, Drag.Data,, sKey).EnsureVisible
- TextBox1.Text = $iKey & ", " & sKey & ", " & Drag.Data
- FunctionKey = "Drop Event"
- UpdateDisplay
From - Gianluigi. V2
Cheers - Quin.
I code therefore I am
I code therefore I am
1 guest and 0 members have just viewed this.


