Drag grid item to another grid
Moderator: Rathinagiri
- serge_girard
- Posts: 3170
- Joined: Sun Nov 25, 2012 2:44 pm
- DBs Used: 1 MySQL - MariaDB
2 DBF - Location: Belgium
- Contact:
Drag grid item to another grid
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
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 442 times
There's nothing you can do that can't be done...
Re: Drag grid item to another grid
Hi Serge,
I scribbled something like that.
I hope it will be helpful.
PS. I added a few improvements.
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
- Attachments
-
- demo.7z
- (1.09 MiB) Downloaded 434 times
Last edited by edk on Fri Dec 08, 2017 12:45 am, edited 2 times in total.
- serge_girard
- Posts: 3170
- Joined: Sun Nov 25, 2012 2:44 pm
- DBs Used: 1 MySQL - MariaDB
2 DBF - Location: Belgium
- Contact:
Re: Drag grid item to another grid
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
Thank you so much, really appreciate this kind of help!
Coding is short and effective. Now reading coding to see how it works...
Serge
There's nothing you can do that can't be done...
-
- Posts: 190
- Joined: Wed Jan 06, 2010 5:39 pm
Re: Drag grid item to another grid
Very interesting!
Re: Drag grid item to another grid
Gracias !
Andrés González López
Desde Guadalajara, Jalisco. México.
Desde Guadalajara, Jalisco. México.
- Rathinagiri
- Posts: 5471
- Joined: Tue Jul 29, 2008 6:30 pm
- DBs Used: MariaDB, SQLite, SQLCipher and MySQL
- Location: Sivakasi, India
- Contact:
Re: Drag grid item to another grid
Wow! Awesome!
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
South or North HMG is worth.
...the possibilities are endless.
- Rathinagiri
- Posts: 5471
- Joined: Tue Jul 29, 2008 6:30 pm
- DBs Used: MariaDB, SQLite, SQLCipher and MySQL
- Location: Sivakasi, India
- Contact:
Re: Drag grid item to another grid
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
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.
South or North HMG is worth.
...the possibilities are endless.
- serge_girard
- Posts: 3170
- Joined: Sun Nov 25, 2012 2:44 pm
- DBs Used: 1 MySQL - MariaDB
2 DBF - Location: Belgium
- Contact:
Re: Drag grid item to another grid
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
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
There's nothing you can do that can't be done...
Re: Drag grid item to another grid
Hi.
I'm trying to fabricate the universal DragAndDrop support.
My intention was not to change HMG sources and create additional events for controls, but only to use available methods.
I thought to use the existing "GetFocus" event.
The projects are not complete yet and free of errors, but I present to the wider circle for its evaluation and suggestions.
I study the behavior of events and I still have a lot to catch up .
The current version supports GRID, TEXTBOX, EDITBOX, RICHEDITBOX controls.
Because TextBox and Editbox are not able to handle the DragAndDrop event with the left mouse button (do a text selection), I did DragAndDrop with the right mouse button.
There is also a function that returns the value with which the mouse button was made DragAndDrop. You can use it to, for example, create a context menu .
I am sending source and demo in the attachment.
The demo supports the following DragAndDrop events:
from Form_1: Grid_1 to Form_2: Grid_1 - copies the dragged content of the cell.
from Form_1: Grid_1 to Form_3: Grid_1 with the left mouse button - copies the entire row that has been dragged.
from Form_1: Grid_1 to Form_3: Grid_1 with the right mouse button - displays a context menu with dynamic options: add / insert a dragged row; replace the current line with data from the line being dragged; move from Form_1: Grid1 dragged row.
from Form_2: Grid_1 to any Form_2 control - it copies the contents of the cell (it also copies cells within itself)
You can copy from any controls of all forms to each control type TEXTBOX, EDITBOX and RICHEDITBOX of Form_2
From Form_3: Grid_1 to Form_1: Grid_2 - moves the entire row.
Available functions:
HMG_Is_DaD () - determines whether the DragAndDrop operation was performed. We can then specify different behaviors for the GotFocus event, depending on whether it is a real event or just simulated by DragAndDrop.
HMG_DaD_Drag_Window () - the name of the window from which DragAndDrop was started
HMG_DaD_Drag_Control () - name of the control from which the data was dragged
HMG_DaD_Drop_Window () - the name of the window in which the data was dropped.
HMG_DaD_Drop_Control () - name of the control in which the data was dropped.
HMG_DaD_DragCellRow () - the Grid row from which the data was dragged (only for GRID)
HMG_DaD_DragCellCol () - the Grid column from which the data was dragged (only for GRID)
HMG_DaD_DropCellRow () - the Grid row on which data has been dropped (only for GRID). If dropped in empty space, it will equal to 0
HMG_DaD_DropCellCol () - the Grid column on which data has been dropped (only for GRID)). If dropped in empty space, it will equal to 0
HMG_DaD_Value () - value of dragged data, it is always an array, for a row Grid consisting of all cells in a row. For TEXT it's a value as one-dimensional array.
HMG_DaD_CellValue () - cell value (GRID)/ value (TEXT) of dragged data
HMG_Is_RButtonDaD() - it return the value .T. if DragAndDrop was using with the right mouse button.
HMG_Release_DaD () - releases the saved values for DragAndDrop.
To use the DragAndDrop function, add DragAndDrop.prg to your project.
In the source of the main program, you should initiate the DragAndDrop support via
command: EnableDragAndDrop ()
Disabling DragAndDrop support via: DisableDragAndDrop ().
Enjoy.
I apologize for my hopeless English.
I'm trying to fabricate the universal DragAndDrop support.
My intention was not to change HMG sources and create additional events for controls, but only to use available methods.
I thought to use the existing "GetFocus" event.
The projects are not complete yet and free of errors, but I present to the wider circle for its evaluation and suggestions.
I study the behavior of events and I still have a lot to catch up .
The current version supports GRID, TEXTBOX, EDITBOX, RICHEDITBOX controls.
Because TextBox and Editbox are not able to handle the DragAndDrop event with the left mouse button (do a text selection), I did DragAndDrop with the right mouse button.
There is also a function that returns the value with which the mouse button was made DragAndDrop. You can use it to, for example, create a context menu .
I am sending source and demo in the attachment.
The demo supports the following DragAndDrop events:
from Form_1: Grid_1 to Form_2: Grid_1 - copies the dragged content of the cell.
from Form_1: Grid_1 to Form_3: Grid_1 with the left mouse button - copies the entire row that has been dragged.
from Form_1: Grid_1 to Form_3: Grid_1 with the right mouse button - displays a context menu with dynamic options: add / insert a dragged row; replace the current line with data from the line being dragged; move from Form_1: Grid1 dragged row.
from Form_2: Grid_1 to any Form_2 control - it copies the contents of the cell (it also copies cells within itself)
You can copy from any controls of all forms to each control type TEXTBOX, EDITBOX and RICHEDITBOX of Form_2
From Form_3: Grid_1 to Form_1: Grid_2 - moves the entire row.
Available functions:
HMG_Is_DaD () - determines whether the DragAndDrop operation was performed. We can then specify different behaviors for the GotFocus event, depending on whether it is a real event or just simulated by DragAndDrop.
HMG_DaD_Drag_Window () - the name of the window from which DragAndDrop was started
HMG_DaD_Drag_Control () - name of the control from which the data was dragged
HMG_DaD_Drop_Window () - the name of the window in which the data was dropped.
HMG_DaD_Drop_Control () - name of the control in which the data was dropped.
HMG_DaD_DragCellRow () - the Grid row from which the data was dragged (only for GRID)
HMG_DaD_DragCellCol () - the Grid column from which the data was dragged (only for GRID)
HMG_DaD_DropCellRow () - the Grid row on which data has been dropped (only for GRID). If dropped in empty space, it will equal to 0
HMG_DaD_DropCellCol () - the Grid column on which data has been dropped (only for GRID)). If dropped in empty space, it will equal to 0
HMG_DaD_Value () - value of dragged data, it is always an array, for a row Grid consisting of all cells in a row. For TEXT it's a value as one-dimensional array.
HMG_DaD_CellValue () - cell value (GRID)/ value (TEXT) of dragged data
HMG_Is_RButtonDaD() - it return the value .T. if DragAndDrop was using with the right mouse button.
HMG_Release_DaD () - releases the saved values for DragAndDrop.
To use the DragAndDrop function, add DragAndDrop.prg to your project.
In the source of the main program, you should initiate the DragAndDrop support via
command: EnableDragAndDrop ()
Disabling DragAndDrop support via: DisableDragAndDrop ().
Enjoy.
I apologize for my hopeless English.
- Attachments
-
- DragAndDrop.7z
- (1.07 MiB) Downloaded 425 times
- serge_girard
- Posts: 3170
- Joined: Sun Nov 25, 2012 2:44 pm
- DBs Used: 1 MySQL - MariaDB
2 DBF - Location: Belgium
- Contact:
Re: Drag grid item to another grid
Great and many thanks!
I will take a look at it asap!
Serge
I will take a look at it asap!
Serge
There's nothing you can do that can't be done...