Drag grid item to another grid

Utilities like DBU, Make, IDE written in HMG/ used to create HMG based applications

Moderator: Rathinagiri

User avatar
serge_girard
Posts: 2762
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 1039 times
Been thanked: 190 times
Contact:

Re: Drag grid item to another grid

Post by serge_girard »

Great Work Edward !

One question : would it also be possible to COPY to grid2 with CTRL-key (now it is always MOVEd)?

Serge
Serge Now Is The Happiest Time Of Your Life !

edk
Posts: 699
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 191 times
Been thanked: 633 times

Post by edk »

serge_girard wrote:
Fri Jan 04, 2019 3:14 pm
Great Work Edward !

One question : would it also be possible to COPY to grid2 with CTRL-key (now it is always MOVEd)?

Serge
What to do during the DragAndDrop operation depends on how you program this event.
You have the following functions:
HMG_DaD_Drag_Window () -> returns the name of the form from which the drag started.
HMG_DaD_Drag_Control () -> returns the name of the control from which the drag started.
HMG_DaD_Drop_Window () -> returns the name of the form on which it was dropped.
HMG_DaD_Drop_Control () -> returns the name of the control on which it was dropped.
HMG_DaD_DragTreeValue () -> returns the value of the position of the tree from which the drag began.
HMG_DaD_DropTreeValue () -> returns the value of the tree position on which it was dropped.
HMG_Is_RButtonDaD () -> returns .T. if dragging was with the right mouse button.

Replace this function to copy from tree # 1 to tree # 2 with the right mouse button or with the ALT key.

Code: Select all

Function Drag_Tree2()
Local cDragFName := HMG_DaD_Drag_Window()
Local cDragCName := HMG_DaD_Drag_Control()
Local cDropFName := HMG_DaD_Drop_Window()
Local cDropCName := HMG_DaD_Drop_Control()
Local nDragTreeValue := HMG_DaD_DragTreeValue()
Local nDropTreeValue := HMG_DaD_DropTreeValue()
Local lIsDraggedWithRightButton := HMG_Is_RButtonDaD()
Local lCopy, aDragItems, nAddPos

IF HMG_Is_DaD()
	HMG_Release_DaD()
	DO CASE
		CASE cDropCName == 'Tree_2' 
			//Move nodes/items
			lCopy := HMG_VirtualKeyIsPressed (VK_LCONTROL) .OR. HMG_VirtualKeyIsPressed (VK_RCONTROL) .OR. HMG_VirtualKeyIsPressed (VK_ALT) .OR. lIsDraggedWithRightButton
			aDragItems := _GetTreeItemStru( cDragFName, cDragCName, nDragTreeValue )
			IF !EMPTY ( aDragItems )
				IF !lCopy .AND. nDropTreeValue < nDragTreeValue		//dropped above the drag
					DoMethod (cDragFName, cDragCName, "DeleteItem", nDragTreeValue)
				ENDIF
				
				nAddPos := nDropTreeValue
				AEVAL ( aDragItems, { |x| ( DoMethod (cDropFName, cDropCName, "AddItem", x[2] , nAddPos + x[3] ),  IF( x[3]=0 /* 1-st item added as last nodes item */, nAddPos := nAddPos + LEN( _GetTreeItemStru( cDropFName, cDropCName, nDropTreeValue ) ) - 1 - x [1] , Nil) ) } )
				
				IF !lCopy .AND. nDropTreeValue > nDragTreeValue		//dropped below the drag
					DoMethod (cDragFName, cDragCName, "DeleteItem", nDragTreeValue)
				ENDIF

				DoMethod (cDropFName, cDropCName, "Redraw")
				DoMethod (cDragFName, cDragCName, "Redraw")		
		
			ENDIF
			
		ENDCASE
ENDIF

RETURN
Control and Shift key disrupt the action of DragAndDrop (they trigger a separate event while dragging) but you can read their value when dropped. So just before dropping, press and hold Control and then drop.

User avatar
serge_girard
Posts: 2762
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 1039 times
Been thanked: 190 times
Contact:

Post by serge_girard »

Great !

Serge
Serge Now Is The Happiest Time Of Your Life !

User avatar
mustafa
Posts: 1084
Joined: Fri Mar 20, 2009 11:38 am
DBs Used: DBF
Location: Alicante - Spain
Has thanked: 25 times
Been thanked: 283 times
Contact:

Post by mustafa »

Edk
Very interesting
Congratulations
Mustafa

User avatar
mol
Posts: 3533
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 292 times
Been thanked: 212 times
Contact:

Post by mol »

Great work!
It would be excellent to have colorized new parent element in the tree while dragging child.

Thank you very much, Edward!

User avatar
Anand
Posts: 556
Joined: Tue May 24, 2016 4:36 pm
DBs Used: DBF
Has thanked: 245 times
Been thanked: 85 times

Post by Anand »

Thanks Edward for such a useful enhancement !!

Regards,

Anand
Regards,

Anand

Image

User avatar
quartz565
Posts: 634
Joined: Mon Oct 01, 2012 12:37 pm
Location: Thessaloniki, Greece
Has thanked: 245 times
Been thanked: 32 times
Contact:

Post by quartz565 »

Thank you Edward!
Best Regards,
Nikos.

os: Windows Server 2012 - 64
hw: HP Server E5606, 2.13GHz, 8.00 GB - Intel Xeon CPU

edk
Posts: 699
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 191 times
Been thanked: 633 times

Post by edk »

mol wrote:
Sat Jan 05, 2019 7:10 am
Great work!
It would be excellent to have colorized new parent element in the tree while dragging child.

Thank you very much, Edward!
Marku, mówisz i masz :D
Marek. You say, and you have. :D
DragAndDrop_0.005.zip
(11.84 KiB) Downloaded 158 times
Tree DragAndDrop.gif
Tree DragAndDrop.gif (77.57 KiB) Viewed 3220 times

User avatar
mol
Posts: 3533
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 292 times
Been thanked: 212 times
Contact:

Post by mol »

Jesteś wielki!
Król Edward na 3 Króli! :-D

Ps. Jakim programem robisz te animowane gify?

edk
Posts: 699
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 191 times
Been thanked: 633 times

Post by edk »

Dzięki, gify zrobilem oCam'em

Post Reply