Drag and drop one cell between listboxes

I have listbox1 with 1 column, and listbox2 with 2 columns.
In listbox2, all the cells of the second column are empty.
Now I want to drag and drop a cell from listbox1 into an empty cell in the second column of listbox2.
How can I solve this problem ?

What have you tried? how has it failed?

Hi Dave,

For listbox1

I set EnableDrag = True and SelectionType = Single
In the DragRow-event : drag.text=Me.List(row)
Return True //allow the drag

For listbox2

I set Me.AcceptTextDrop in the open-event.
In the DropObject : Me.AddRow obj.text

When I run the program and I drag the text in a cell from listbox1, to listbox2, the program adds a new row in listbox2

[quote=106404:@Antoon Verleysen]
For listbox1

I set EnableDrag = True and SelectionType = Single
In the DragRow-event : drag.text=Me.List(row)
Return True //allow the drag

For listbox2

I set Me.AcceptTextDrop in the open-event.
In the DropObject : Me.AddRow obj.text

When I run the program and I drag the text in a cell from listbox1, to listbox2, the program adds a new row in listbox2[/quote]

See http://documentation.xojo.com/index.php/ListBox.DragRow

Add the Dragrow event to Listbox1 :

Function DragRow(Drag as DragItem, Row as Integer) as Boolean Drag.Text=ListBox1.List(Row) Return True

I tested it successfully here.

Hallo Michel,

Tx.
But I putted already that code in the DragRow-event.
When the program runs there is a ROW added !!! Instead of only replacing the value of one cell in listbox2

Additional remark : I want to drag and drop a CELL not a ROW !

Antoon, in the code you posted you have “addrow”, and of course that adds a row.

Have you tried Michel’s code? (I realize it is not what you want, anyway)

Julen.

Tx for your reply.
My code is exactly the same as Michel’s code (see my second post)
I realize that the problem = ADDROW !
Unfortunately ADDCELL doesn’t exist !
Can I solve my problem with a sort of trick ?

[quote=106435:@Antoon Verleysen]Tx for your reply.
My code is exactly the same as Michel’s code (see my second post)
I realize that the problem = ADDROW !
Unfortunately ADDCELL doesn’t exist !
Can I solve my problem with a sort of trick ?[/quote]

Instead of addrow, in DropObject use MouseX and MouseY to know where the cursor is and calculate what is the cell underneath. MouseY divided by rowheight and MouseX relative to columns width, Then go

Me.Cell(row, column) = obj.text

Tx Michel.
I’ll try it out.

Antoon,
if you get that working - it would be nice if you could post here the complete working code - so that others can also learnt from it (myself included) :slight_smile:

Hi guys,
Thanks for all your help.

And here is the complete working code. Yes, indeed, it certainly works !!

For listbox1 (= source)
In the inspector :
Enabledrag = ON
SelectionType = Single
In the DragRow - event :
drag.text = Me.List(row)
Return True

For listbox2 (= target)
In the Open - event :
Me.AcceptYexyDrop
In the DropObject - event :
Dim TargetColumn As Integer
TargetColumn = 1 // this is the second column in the listbox
Me.Cell((MouseY-Me.top)\Me.RowHeight, TargetColumn) = obj.text

Remarks :
Listbox1 has only 1 column.
Both listboxes doesn’t have headers.

With my special thanks for Michel Bujardet, the man who gave me the golden tip !!!

Rectification :
It is not “Me.AcceptYexyDrop” but “Me.AcceptTextDrop”

AcceptYexyDrop :slight_smile:

New sample projects are bundled with the new release (2014r2) and it seems an example of drag and dropping between cells has been added. Maybe worth checking it.

You can find the list of new sample projects here:
https://forum.xojo.com/13454-added-20-new-example-projects

Julen

I checked it out : cool !
Now trying to use the code with 2 listboxes !!!

Keep in mind this does not take into account if the listbox is scrolled.

me.cell((mouseY-me.top)\me.rowHeight + me.scrollPosition, targetColumn) = obj.text

Thanks for the tip, Peter.
I adapted my code.