Drag grid item to another grid

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

Moderator: Rathinagiri

Post Reply
User avatar
serge_girard
Posts: 1903
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 314 times
Been thanked: 74 times
Contact:

Drag grid item to another grid

Post by serge_girard » Wed Dec 06, 2017 1:29 pm

Hello,

A few years ago we had a demo that could 'drag' explorer files names to a HMG grid. (I will att demo in RAR file, for the ones who missed it).
Thanks to Grigory Filatov, Claudio Soto and Pablo César Arrascaeta.

This demo I wanted to use to drag grid items from one to another grid.
No files or involved, just 'copy' a grid-row in a form to another grid in another form, within the same application, of course.
So I have 2 forms opened with a both a grid and now I want to 'move or copy' a line (or multi-lines) to the second form.

Anybody has such demo or knows how to?

Thanks, Serge
Attachments
DRAG.rar
(1.21 MiB) Downloaded 29 times

edk
Posts: 194
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 55 times
Been thanked: 121 times

Post by edk » Thu Dec 07, 2017 1:23 pm

Hi Serge,

I scribbled something like that.
I hope it will be helpful.

Code: Select all

#include <hmg.ch>

Function Main()
Private aRows1 [21] [3], aRows2 [0] [4], aRows3 [0] [2], aRows4 [0] [3]

aRows1  [1]  := {'Simpson',  'Homer',    '555-5555'}
aRows1  [2]  := {'Mulder',   'Fox',      '324-6432'}
aRows1  [3]  := {'Smart',    'Max',      '432-5892'}
aRows1  [4]  := {'Grillo',   'Pepe',     '894-2332'}
aRows1  [5]  := {'Kirk',     'James',    '346-9873'}
aRows1  [6]  := {'Barriga',  'Carlos',   '394-9654'}
aRows1  [7]  := {'Flanders', 'Ned',      '435-3211'}
aRows1  [8]  := {'Smith',    'John',     '123-1234'}
aRows1  [9]  := {'Pedemonti','Flavio',   '000-0000'}
aRows1 [10]  := {'Gomez',    'Juan',     '583-4832'}
aRows1 [11]  := {'Fernandez','Raul',     '321-4332'}
aRows1 [12]  := {'Borges',   'Javier',   '326-9430'}
aRows1 [13]  := {'Alvarez',  'Alberto',  '543-7898'}
aRows1 [14]  := {'Gonzalez', 'Ambo',     '437-8473'}
aRows1 [15]  := {'Batistuta','Gol',      '485-2843'}
aRows1 [16]  := {'Vinazzi',  'Amigo',    '394-5983'}
aRows1 [17]  := {'Pedemonti','Flavio',   '534-7984'}
aRows1 [18]  := {'Samarbide','Armando',  '854-7873'}
aRows1 [19]  := {'Pradon',   'Alejandra','???-????'}
aRows1 [20]  := {'Reyes',    'Monica',   '432-5836'}
aRows1 [21]  := {'Fernández','Vicente',  '000-0000'}

CREATE EVENT PROCNAME MouseDragGRID()

DEFINE WINDOW Form_1 ;
    AT 0,0 ;
    WIDTH 426 ;
    HEIGHT 650 ;
    TITLE 'Grid Events Demo - Drag Demo Form 1' ;
    MAIN NOSIZE
   
    @ 10,10 GRID Grid_1 ;
        WIDTH 400 ;
        HEIGHT 330 ;
        HEADERS {'Column 1','Column 2','Column 3'} ;
        WIDTHS {120,120,120} ;
        ITEMS aRows1 ;
        VALUE {1,1} ;
        CELLNAVIGATION

  @ 360,10 GRID Grid_2 ;
        WIDTH 400 ;
        HEIGHT 250 ;
        HEADERS {'Column 1','Column 2','Column 3'} ;
        WIDTHS {120,120,120} ;
        ITEMS aRows4 ;
        VALUE {1,1} ;
		CELLNAVIGATION

END WINDOW

DEFINE WINDOW Form_2 ;
    AT 0,435 ;
    WIDTH 426 ;
    HEIGHT 395 ;
    TITLE 'Grid Events Demo - Drag Demo Form 2'
   
    @ 10,10 GRID Grid_1 ;
        WIDTH 400 ;
        HEIGHT 330 ;
        HEADERS {'Column 1','Column 2','Column 3','Column 4'} ;
        WIDTHS {120,120,120,120} ;
        ITEMS aRows2 ;
        VALUE {1,1} ;
        CELLNAVIGATION

END WINDOW

DEFINE WINDOW Form_3 ;
    AT 0,860 ;
    WIDTH 326 ;
    HEIGHT 395 ;
    TITLE 'Grid Events Demo - Drag Demo Form 3'
   
    @ 10,10 GRID Grid_1 ;
        WIDTH 300 ;
        HEIGHT 330 ;
        HEADERS {'Column 1','Column 2'} ;
        WIDTHS {120,120} ;
        ITEMS aRows3 ;
        VALUE {1,1} ;
        CELLNAVIGATION

END WINDOW

ACTIVATE WINDOW Form_1, Form_2, Form_3

Return Nil


*************
FUNCTION MouseDragGRID()
STATIC nLastMsg, aDragGRID
LOCAL  nHWnd:=EventHWND ()
LOCAL  nMsg:=EventMSG ()
LOCAL  nWParam:=EventWPARAM ()
LOCAL  nLParam:=EventLPARAM ()
LOCAL i := ASCAN ( _HMG_SYSDATA [3] ,  nHWnd )
LOCAL cGridName:="" , cFormName:="", j, aRowGrid:={}		//, nRowDrag


IF i > 0 .AND. ( _HMG_SYSDATA [1] [i] == "GRID" .OR. _HMG_SYSDATA [1] [i] == "MULTIGRID" )		//GRID detect

	IF VALTYPE(aDragGRID)="A"
		SetWindowCursor (nHWnd, IF ( aDragGRID [1] == nHWnd, "HMG_DRAGUP", "HMG_DRAGDOWN" ) )	//change mouse cursor
	ELSE
		SetWindowCursor (nHWnd, IDC_ARROW)														//restore mouse cursor
	ENDIF

	IF nMsg == WM_MOUSEMOVE .AND. nLastMsg == WM_MOUSEMOVE
		IF nWParam == MK_LBUTTON					//MouseDrag detect
			IF aDragGRID=Nil .AND. _GetGridCellData (i) [1]>0				//If not stored drag data and not empty grid
				//nRowDrag:=_GetGridCellData (i) /* { CellRowClicked, CellColClicked } */
				GetControlNameByHandle (nHWnd, @cGridName, @cFormName)
				FOR j=1 TO GetProperty(cFormName, cGridName, "ColumnCOUNT")
					AADD(aRowGrid, GetProperty(cFormName, cGridName, "CellEx", _GetGridCellData (i) [1], j ) )
				NEXT j
				aDragGRID:={nHWnd, aRowGrid }			//store drag data: handle of grid "from" and row data
			ENDIF	
		ENDIF
		
	ELSEIF VALTYPE(aDragGRID)="A" .AND. nMsg == WM_LBUTTONUP		//IF stored drag data and released left button
		IF aDragGRID [1] # nHWnd					//left button released on another grid 
			//nRowDrag:=_GetGridCellData (i) /* { CellRowReleased, CellColReleased } */	
			GetControlNameByHandle (nHWnd, @cGridName, @cFormName)
			FOR j=1 TO GetProperty(cFormName, cGridName, "ColumnCOUNT")
				IF j <= LEN( aDragGRID [2] )
					AADD(aRowGrid, aDragGRID [2] [j] )
				ELSE
					AADD(aRowGrid, Nil )
				ENDIF
			NEXT j
			//drop row data
			DoMethod( cFormName,;
				  cGridName,;
				  "AddItemEx",;
				  aRowGrid,;
				  IF( _GetGridCellData (i) [1] = 0, GetProperty(cFormName, cGridName, "ItemCount") + 1 /* add new row */ , _GetGridCellData (i) [1] /* Insert new row */) )
		ENDIF
		aDragGrid:=Nil						//release drag data
	
	ENDIF
ELSEIF nMsg == WM_MOUSEMOVE .AND. nLastMsg == WM_MOUSEMOVE .AND. nWParam # MK_LBUTTON .AND. VALTYPE(aDragGRID)="A" //canceled drag
		aDragGrid:=Nil	//release drag data	
ENDIF
nLastMsg:=EventMSG()
RETURN NIL
PS. I added a few improvements.
Attachments
demo.7z
(1.09 MiB) Downloaded 14 times
Last edited by edk on Fri Dec 08, 2017 12:45 am, edited 2 times in total.

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

Post by serge_girard » Thu Dec 07, 2017 1:56 pm

YES !

Thank you so much, really appreciate this kind of help!
Coding is short and effective. Now reading coding to see how it works...

Serge

chrisjx2002
Posts: 155
Joined: Wed Jan 06, 2010 5:39 pm
Been thanked: 2 times

Post by chrisjx2002 » Thu Dec 07, 2017 3:13 pm

Very interesting!

User avatar
andyglezl
Posts: 858
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Has thanked: 7 times
Been thanked: 25 times
Contact:

Post by andyglezl » Thu Dec 07, 2017 9:32 pm

Gracias !
Andrés González López
Desde Guadalajara, Jalisco. México.

User avatar
Rathinagiri
Posts: 5181
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 141 times
Been thanked: 131 times
Contact:

Post by Rathinagiri » Fri Dec 08, 2017 4:13 am

Wow! Awesome!
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

User avatar
Rathinagiri
Posts: 5181
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 141 times
Been thanked: 131 times
Contact:

Post by Rathinagiri » Fri Dec 08, 2017 4:23 am

Now, I think you can help to write a UNIVERSAL function to take care of dragging data between controls and windows.

For example, a LISTBOX item can be dragged to a TEXTBOX for editing or a TEXTBOX data can be dragged to a LISTBOX adding into it.

If source columns and destination columns are unique, GRID data can be dragged to another GRID as you have done already above.

It is enough if the function gives the following informations to the developer.

1. Control/Window names from which the data are dragged
2. Control/Window names from which the data are dragged
3. Details of Listbox item(s) or Grid item(s) being dragged
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

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

Post by serge_girard » Fri Dec 08, 2017 8:23 am

Yes Rathi, I was also thinking of that.

And multiselect as well, if possible.

The DRAG.rar I posted drags items from a non-HMG application (explorer list). How about 'dragging' from other applications? Is this also possible?

Serge

Post Reply