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: 2519
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 823 times
Been thanked: 154 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

edk
Posts: 581
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 148 times
Been thanked: 510 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: 2519
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 823 times
Been thanked: 154 times
Contact:

Post by serge_girard »

Great !

Serge

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

Post by mustafa »

Edk
Very interesting
Congratulations
Mustafa

User avatar
mol
Posts: 3367
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 260 times
Been thanked: 164 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: 499
Joined: Tue May 24, 2016 4:36 pm
DBs Used: DBF
Has thanked: 193 times
Been thanked: 79 times

Post by Anand »

Thanks Edward for such a useful enhancement !!

Regards,

Anand
Image

User avatar
quartz565
Posts: 598
Joined: Mon Oct 01, 2012 12:37 pm
Location: Thessaloniki, Greece
Has thanked: 206 times
Been thanked: 23 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: 581
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 148 times
Been thanked: 510 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 58 times
Tree DragAndDrop.gif
Tree DragAndDrop.gif (77.57 KiB) Viewed 1286 times

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

Post by mol »

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

Ps. Jakim programem robisz te animowane gify?

edk
Posts: 581
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 148 times
Been thanked: 510 times

Post by edk »

Dzięki, gify zrobilem oCam'em

Post Reply