Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Primer on Drag drop
Message
From
02/07/2016 16:48:10
 
 
To
02/07/2016 13:59:18
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 8.1
Network:
Windows Server 2012 R2
Database:
Visual FoxPro
Application:
Desktop
Virtual environment:
VMWare
Miscellaneous
Thread ID:
01637889
Message ID:
01637891
Views:
123
This message has been marked as the solution to the initial question of the thread.
>Hi all,
>
>Has anyone written any white papers on using drag and drop in VFP? Have *never* used this feature but finally a client has a use for it.
>
>Specifically, they want to be able to drag files from their file system overtop of a VFP grid and drop them to upload them to the grid. By "upload" I mean that I would get a list of the files (including full path) that I would then loop through and add to their documents database.
>
>(so if no one has a "primer", if anyone has code snippets I could look at, that would be great!
>
>Albert

Hopefully, this will get you started.
#include "FOXPRO.H"

LOCAL loTheForm AS filesInGrid

m.loTheForm = CREATEOBJECT("filesInGrid")
m.loTheForm.Show(1)

m.loTheForm = .NULL.

DEFINE CLASS filesInGrid AS Form

	ADD OBJECT grdFiles AS Grid WITH Top = 20, ReadOnly = .T.
	
	FUNCTION grdFiles.Init
	
		* The grid can receive draggable objects
		This.OLEDropMode = 1
		
		* create a cursor for the grid
		CREATE CURSOR curFiles (displayname C(80), filename M)

		This.RecordSource = "curFiles"
		This.ColumnCount = 1
		This.Column1.Width = This.Width - 24
	
	ENDFUNC

	* when a data object is dragged over the grid
	FUNCTION grdFiles.OLEDragOver
	LPARAMETERS oDataObject, nEffect, nButton, nShift, nXCoord, nYCoord, nState
	
		* if it is a file collection, say that we can receive a link to the files
		IF m.oDataObject.GetFormat(CF_FILES)
			m.nEffect = DROPEFFECT_LINK
		* otherwise, we are not interested
		ELSE
			m.nEffect = DROPEFFECT_NONE
		ENDIF
		
	ENDFUNC

	* when a data object is dropped over the grid
	FUNCTION grdFiles.OLEDragDrop
	LPARAMETERS oDataObject, nEffect, nButton, nShift, nXCoord, nYCoord
	LOCAL ARRAY laFiles [1]
	LOCAL lnFile AS Integer
	LOCAL lcFileName AS String
	
		* if it is a file collection, process the file collection
		IF m.oDataObject.GetFormat(CF_FILES)

			IF m.oDataObject.GetData(CF_FILES, @m.laFiles)
			
				SELECT curFiles
				
				FOR m.lnFile = 1 TO ALEN(m.laFiles)

					* add the filename, if it is not already in the collection
					LOCATE FOR filename == m.laFiles[m.lnFile]
					IF !FOUND()
						INSERT INTO curFiles (displayname, filename) ;
							VALUES (JUSTSTEM(m.laFiles[m.lnFile]), m.laFiles[m.lnFile])
					ENDIF

				ENDFOR

				This.Refresh()

			ENDIF

			* signal that a link was performed			
			m.nEffect = DROPEFFECT_LINK

		* otherwise, we are not interested
		ELSE
			m.nEffect = DROPEFFECT_NONE
		ENDIF

	ENDPROC

		
ENDDEFINE
----------------------------------
António Tavares Lopes
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform