Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drag and drop from a grid to a grid

Status
Not open for further replies.

Doug Lindauer

Programmer
Feb 2, 2017
38
US
I have 2 grids connected to 2 tables and I'd like to enable drag and drop between a cell on one grid to the cell on the other but nothing I do seems to make it work. The solutions app shows drag and drop between a listbox and a textbox and I can make that work but not the grid control.

Nothing I've found seems to address this so I've had to make some assumptions. I assume I have to work on the OLEDragDrop method on the textbox in the destination column and the textbox in the source column. So this is where I'm at and it doesn't work. I can make individual textboxes drag and drop but not grid control text boxes.

This is the code I'm using in both places in the grids
Code:
[tt]grdSOURCE.colSOURCE.txtSOURCE
  OLEDragMode = 1 - Automatic

grdDEST.colDEST.txtDEST
  OLEDropMode = 1 - enabled
  OLEDragMode = 0 - manual
  OLEDragDrop code:
      lparameters oDataObject, nEffect, nButton, nShift, nXCoord, nYCoord

      if oDataObject.Getformat(1)	&&CF_TEXT
	  This.Value = oDataObject.GetData(1)
      endif
      nodefault
[/tt]

It's unclear to me if the oDataObject thing is just the textbox or something more so I just have to assume it's the textbox control or the value in the control.
 
Even when it works you have cell value drag&drop only. When you want to ext4end this to selections you better embed excel grids or get an ActiveX grid control.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Cell value drag/drop is all I need. It's not a big thing for this project, just a nice-to-have if I can make it work. I've never fiddled with OLE before. I'm a database guy, not a microsoft expert. I'm amazed (sort of) that it doesn't work so I'm hoping someone can tell me how to do it. At this point I've spent several hours on it and the documentation and sample code aren't helping. I have the feeling that there's some setting somewhere that's keeping this from working. Why would it work between 2 independent textboxes and not 2 textboxes in a grid? I'll figure it out eventually on my own but it would be nice if someone out there knew the answer.
 
For OLE drag-and-drop to work, you need code in OLEDragOver as well as OLEDragDrop. In OLEDragOver, you need to set OLEDropHasData (and maybe OLEDropEffects).

I wrote a whole paper on drag-and-drop for last year's Southwest Fox conference. It's not on my website yet, but if you shoot me an email, I'll send it to you. tamar at tomorrowssolutionsllc.com

Tamar
 
Tamar, I guess that's most helpful, the sample code in VFP samples "fun with OLE drag&drop" also shows that, but indeed between two textboxes you only need to set OLEDragMode=1 (Automatic) for a Source and OleDropMode=1 (Enabled) to a drag target textbox and it works.

I checked for grids you then have to set OleDropmode at the Grid level, and not only that, Ole events don't fire in the individual grid column controls, they fire on the grid level.

In this example Yousfi handles the OleDragDrop in inserting a new record into the Grid recordsource:

To get to cells I don't see how you could forward events to the individual grid cells, the main problem is there only is one textbox for a column, not for every cell, so by default you could only drop on the active row of a grid, anywhere else first needs to be activated. Cetins sample also shows that you have to call ActivateCell with the info of GridHitTest so Grid.OleDragDrop can put the dragged value into the activated cells textbox value.

Bye, Olaf.



Olaf Doschke Software Engineering
 
Olaf,
Maybe I have overlooked, but have meanwhile downloaded all of Yousfi's samples in this blog about Drag & Drop. However dont see anything that drops into a gridsource.
Koen
 
Koen,

Dropping onto a grid is no different from dropping onto any other control. You just need to keep in mind that is the grid that receives the relevant event, not the column.

Of course, what you do with the object being dragged is another matter. If the aim is to add it to the grid (which would be what the user expects), you would have to work out which row and column was the drop target, and update the underlying cursor accordingly.

Doug,

If I was in your situation, I think I would look for some other solution (other than drag-and-drop), such as a context menu with an option to copy the selected value to the other grid (but you would still need some way of identifying the target cell).

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Koen, there are multiple samples on that page, but yes, there only is code about a grid as drop target. It's the harder part to enable a grid cell to be the drop target, though, drop yourse is simply done by setting OleDragMode to 1 (Automatic).

And the aspect of a cell as a target is only handled by Cetin Basoz's code in the thread mgagnon pointed out. I also was talking about that when talking about the need to call GridHitTest and ActvateCell.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Mike, Olaf,

Correct and understood, also noticed that Yousfi's is only indirectly referring to dropping an object in a gridrecordsource, it is more about IE dropping from and to.
What a waste of time to download and install Yousfi's sample's for this aspect. Olaf made me believe Yousfi had made a sample to show the technique. <Quote>In this example Yousfi handles the OleDragDrop in inserting a new record into the Grid recordsource:</Unquote> For this better to concentrate on Cetin's code
Regards,
Koen
 
Koen, that is still true:

Code:
Procedure grid1.OLEDragDrop

Lparameters oDataObject, nEffect, nButton, nShift, nXCoord, nYCoord
Local aValues, i, cText, nOperation

*-- Check to see whether the user wants to copy or move
If nShift == 1
nOperation = 1	&&DROPEFFECT_COPY
Else
nOperation = 2	&&DROPEFFECT_MOVE
Endif

Thisform.LockScreen = .T.

Do Case

[highlight #FCE94F]Case oDataObject.GetFormat(1)		&& Text[/highlight]
[highlight #FCE94F]cText = oDataObject.GetData(1)[/highlight]
Sele This.recorsource

*-- Add the text as a new item in the list
[highlight #FCE94F]Insert Into ycurs Values(m.cText )[/highlight]
Thisform.grid1.Refresh

Case oDataObject.GetFormat(15)	&& Files CF_DROP
Dimension aValues[1]
oDataObject.GetData(15, @aValues )

*-- Add each filename as a new item in the list
For i = 1 To Alen(aValues)
	Insert Into ycurs Values(aValues[m.i])
Next
Thisform.grid1.Refresh

Endcase

Thisform.LockScreen = .F.
*-- Set the nEffect parameter for communication back to the source object
nEffect = nOperation
Endproc

Sorry, I can't help you, if you don't find anything helpful in these samples.

The highlighted lines take droppend Text (from anywhere) and put it into a new record, not into an already existing cell, that's what I said.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Olaf,
OK dropping into a new record, that seems more or less like an Add and Update procedure and not like a Replace replace what D&D usualy is for a grid. Thanks for pointing us to Yousfi's very informative coding examples.

Regards,
Koen

P.S. Meanwhile I have explored once more this sample by Yousfi about drag and drop.
Hmm, It does not drag and drop in the usual way at all, it copies the file location to a cursor ycurs. A more or less sophisticated way of getfile() from IE. Maybe it is doable to change it and make a drag and drop between 2 grids as the usual between two listboxes. Shall have to study the code.
 
Well, once you have the mechnism working, it's up tp you whether you use cText to INSERT INTO a cursor or into a textbox of a grid, isn't it?

And oDataObject.GetFormat(1) becomes true, if the format is text, no matter where that drageged data ceoms from, from a textbox, from a grid cell or even from another application.

OLE is the Drag&Drop variant that's more comüplex, harder to establish, therefore, but also with more features than D&D of text values.

Giid luck, I'm confident you get it going the way you want to, Cetin Basoz example already is further into the goal of activating the target cell. I just pointed to Yousfi as it has several examples adding to all you already have at hand with the pointers of mgagnon, the VFP samples and more you can find in FAQs and you don't have to take code 1:1, if you don't like the code to INSERT INTO a cursor, then don'T.

Bye, Olaf.



Olaf Doschke Software Engineering
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top