copy items from a loaded grid to another grid or virtual grid

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

User avatar
jairpinho
Posts: 420
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Contact:

copy items from a loaded grid to another grid or virtual grid

Post by jairpinho »

hello, I need to copy the items from a grid already loaded to another empty grid or virtual grid, ms I didn't want to use additem with for and next

someone already used something would have some example
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: copy items from a loaded grid to another grid or virtual grid

Post by andyglezl »

Quizá esto...

\HMG\3.4.4\SAMPLES\Controls\Grid\GRID_01\demo.prg

Los 2 Grid´s utilizan el mismo array.
*----------------------------------------------------------------------
Maybe this ...

\HMG\3.4.4\SAMPLES\Controls\Grid\GRID_01\demo.prg

The 2 Grid's use the same array.
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
serge_girard
Posts: 3312
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: copy items from a loaded grid to another grid or virtual grid

Post by serge_girard »

Jair,

This maybe?

Code: Select all

FOR xx :=  1 to Form_1.Grid_1.Itemcount
   aItem       := Form_1.Grid_1.Item ( XX )  

   cITEM1      := STRVALUE(aItem [1] ) 
   cITEM2      := STRVALUE(aItem [2] ) 
   cITEM3      := STRVALUE(aItem [3] ) 
   cITEM9      := STRVALUE(aItem [9] ) 
   cITEM11     := STRVALUE(aItem [11] ) 
   ADD ITEM { cITEM1 , cITEM1 , cITEM3, cITEM9, cITEM11   } TO Grid_2 OF Form_1

NEXT
There's nothing you can do that can't be done...
User avatar
jairpinho
Posts: 420
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Contact:

Re: copy items from a loaded grid to another grid or virtual grid

Post by jairpinho »

serge_girard wrote: Tue Nov 10, 2020 8:16 pm Jair,

This maybe?

Code: Select all

FOR xx :=  1 to Form_1.Grid_1.Itemcount
   aItem       := Form_1.Grid_1.Item ( XX )  

   cITEM1      := STRVALUE(aItem [1] ) 
   cITEM2      := STRVALUE(aItem [2] ) 
   cITEM3      := STRVALUE(aItem [3] ) 
   cITEM9      := STRVALUE(aItem [9] ) 
   cITEM11     := STRVALUE(aItem [11] ) 
   ADD ITEM { cITEM1 , cITEM1 , cITEM3, cITEM9, cITEM11   } TO Grid_2 OF Form_1

NEXT

hello Serge, that's exactly what I don't want to do, I would like to take the array already loaded with additem in grid1 and put it at once in grid 2

follow as you like

aGrid1 := Form_Novo_Pedido.Grid_1.item
Form_Novo_Pedido.Grid_2.additem( aGrid1 )
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br
edk
Posts: 999
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: copy items from a loaded grid to another grid or virtual grid

Post by edk »

Maybe this will be useful:
(simplified version without error handling)

Code: Select all

FOR nRow := 1 TO Form_Novo_Pedido.Grid_1.ItemCount
	Form_Novo_Pedido.Grid_2.AddItem( _GetItem ( 'Grid_1', 'Form_Novo_Pedido' , nRow  ) )
NEXT nRow
Example of new functions: HMG_GetGridAllItems (cForm, cGrid) and HMG_GetGridRowItems (cForm, cGrid, nRow)
(version with error handling)

Code: Select all

#include "hmg.ch"

Function Main

Local aRows [20] [3]


	DEFINE WINDOW Form_1 ;
		AT 0,0 ;
		WIDTH 800 ;
		HEIGHT 550 ;
		TITLE 'Hello World!' ;
		MAIN 

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

		DEFINE TOOLBAR ToolBar_1 BUTTONSIZE 200,20 

		BUTTON B_CLONE CAPTION " Clone to Grid 2 " ACTION CloneGrid()
		BUTTON B_ITEMS CAPTION " List of all items of Grid 2 " ACTION MsgDebug ( HMG_GetGridAllItems ( 'Form_1', 'Grid_2' ) )
		BUTTON B_CLEAN CAPTION " Clean Grid 2 " ACTION Form_1.Grid_2.DeleteAllItems
        
		END TOOLBAR
		
		@ 50,10 GRID Grid_1 ;
			WIDTH 760 ;
			HEIGHT 180 ;
			HEADERS {'Last Name','First Name','Phone'} ;
			WIDTHS {140,140,140};
			ITEMS aRows ;
			VALUE {1,1} ;
			EDIT ;
			JUSTIFY { GRID_JTFY_CENTER,GRID_JTFY_RIGHT, GRID_JTFY_RIGHT } ;
			CELLNAVIGATION 


		@ 240,10 GRID Grid_2 ;
			WIDTH 760 ;
			HEIGHT 180 ;
			HEADERS {'Last Name','First Name','Phone'} ;
			WIDTHS {140,140,140};
			ITEMS {} ;
			VALUE 1
			    	
	END WINDOW

	CENTER WINDOW Form_1

	ACTIVATE WINDOW Form_1

Return


***********************************
Function CloneGrid()
Local i

Form_1.Grid_2.DeleteAllItems
FOR i = 1 TO Form_1.Grid_1.ItemCount
	Form_1.Grid_2.AddItem ( HMG_GetGridRowItems ( 'Form_1', 'Grid_1', i ) )
NEXT i

RETURN
****************************************************************
Function HMG_GetGridAllItems ( cForm, cGrid )
Local aAllItems := {}, nRow
CHECK TYPE cForm AS CHARACTER, ;
           cGrid AS CHARACTER

IF _IsControlDefined ( cGrid , cForm )
	cType := GetControlType ( cGrid, cForm)
	IF cType == "GRID" .OR. cType == "MULTIGRID"
		FOR nRow = 1 TO GetProperty ( cForm, cGrid, 'ItemCount' )
			AADD (aAllItems, _GetItem ( cGrid, cForm , nRow  ) )
		NEXT nRow
	ENDIF
ENDIF
RETURN aAllItems
****************************************************************
Function HMG_GetGridRowItems ( cForm, cGrid, nRow )
Local aRowItems := {}, cType
Default nRow := 1
CHECK TYPE cForm AS CHARACTER, ;
           cGrid AS CHARACTER, ;
           nRow  AS NUMERIC

IF _IsControlDefined ( cGrid , cForm )
	cType := GetControlType ( cGrid, cForm)
	IF ( cType == "GRID" .OR. cType == "MULTIGRID" ) .AND. nRow > 0 .AND. nRow <= GetProperty ( cForm, cGrid, 'ItemCount' )
		aRowItems := _GetItem ( cGrid, cForm , nRow  )
	ENDIF
ENDIF
RETURN aRowItems
User avatar
jairpinho
Posts: 420
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Contact:

Re: copy items from a loaded grid to another grid or virtual grid

Post by jairpinho »

edk wrote: Tue Nov 10, 2020 10:41 pm Maybe this will be useful:
(simplified version without error handling)

Code: Select all

FOR nRow := 1 TO Form_Novo_Pedido.Grid_1.ItemCount
	Form_Novo_Pedido.Grid_2.AddItem( _GetItem ( 'Grid_1', 'Form_Novo_Pedido' , nRow  ) )
NEXT nRow
Example of new functions: HMG_GetGridAllItems (cForm, cGrid) and HMG_GetGridRowItems (cForm, cGrid, nRow)
(version with error handling)

Code: Select all

#include "hmg.ch"

Function Main

Local aRows [20] [3]


	DEFINE WINDOW Form_1 ;
		AT 0,0 ;
		WIDTH 800 ;
		HEIGHT 550 ;
		TITLE 'Hello World!' ;
		MAIN 

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

		DEFINE TOOLBAR ToolBar_1 BUTTONSIZE 200,20 

		BUTTON B_CLONE CAPTION " Clone to Grid 2 " ACTION CloneGrid()
		BUTTON B_ITEMS CAPTION " List of all items of Grid 2 " ACTION MsgDebug ( HMG_GetGridAllItems ( 'Form_1', 'Grid_2' ) )
		BUTTON B_CLEAN CAPTION " Clean Grid 2 " ACTION Form_1.Grid_2.DeleteAllItems
        
		END TOOLBAR
		
		@ 50,10 GRID Grid_1 ;
			WIDTH 760 ;
			HEIGHT 180 ;
			HEADERS {'Last Name','First Name','Phone'} ;
			WIDTHS {140,140,140};
			ITEMS aRows ;
			VALUE {1,1} ;
			EDIT ;
			JUSTIFY { GRID_JTFY_CENTER,GRID_JTFY_RIGHT, GRID_JTFY_RIGHT } ;
			CELLNAVIGATION 


		@ 240,10 GRID Grid_2 ;
			WIDTH 760 ;
			HEIGHT 180 ;
			HEADERS {'Last Name','First Name','Phone'} ;
			WIDTHS {140,140,140};
			ITEMS {} ;
			VALUE 1
			    	
	END WINDOW

	CENTER WINDOW Form_1

	ACTIVATE WINDOW Form_1

Return


***********************************
Function CloneGrid()
Local i

Form_1.Grid_2.DeleteAllItems
FOR i = 1 TO Form_1.Grid_1.ItemCount
	Form_1.Grid_2.AddItem ( HMG_GetGridRowItems ( 'Form_1', 'Grid_1', i ) )
NEXT i

RETURN
****************************************************************
Function HMG_GetGridAllItems ( cForm, cGrid )
Local aAllItems := {}, nRow
CHECK TYPE cForm AS CHARACTER, ;
           cGrid AS CHARACTER

IF _IsControlDefined ( cGrid , cForm )
	cType := GetControlType ( cGrid, cForm)
	IF cType == "GRID" .OR. cType == "MULTIGRID"
		FOR nRow = 1 TO GetProperty ( cForm, cGrid, 'ItemCount' )
			AADD (aAllItems, _GetItem ( cGrid, cForm , nRow  ) )
		NEXT nRow
	ENDIF
ENDIF
RETURN aAllItems
****************************************************************
Function HMG_GetGridRowItems ( cForm, cGrid, nRow )
Local aRowItems := {}, cType
Default nRow := 1
CHECK TYPE cForm AS CHARACTER, ;
           cGrid AS CHARACTER, ;
           nRow  AS NUMERIC

IF _IsControlDefined ( cGrid , cForm )
	cType := GetControlType ( cGrid, cForm)
	IF ( cType == "GRID" .OR. cType == "MULTIGRID" ) .AND. nRow > 0 .AND. nRow <= GetProperty ( cForm, cGrid, 'ItemCount' )
		aRowItems := _GetItem ( cGrid, cForm , nRow  )
	ENDIF
ENDIF
RETURN aRowItems
EDK, thank you what you were looking for how to do
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br
User avatar
AUGE_OHR
Posts: 2095
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: copy items from a loaded grid to another grid or virtual grid

Post by AUGE_OHR »

hi,

how to DragDrop from GRID_1 to GRID_2 :idea:

i have OnCLick which include "mouse click down and up"

what i need is "mouse click down" WM_LBUTTONDOWN and "mouse click up" WM_LBUTTONUP for Start / Stop DragDrop.
have fun
Jimmy
edk
Posts: 999
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: copy items from a loaded grid to another grid or virtual grid

Post by edk »

AUGE_OHR wrote: Wed Nov 11, 2020 12:05 am hi,

how to DragDrop from GRID_1 to GRID_2 :idea:

i have OnCLick which include "mouse click down and up"

what i need is "mouse click down" WM_LBUTTONDOWN and "mouse click up" WM_LBUTTONUP for Start / Stop DragDrop.
My solution for grids, edit boxes, rich edit boxes, texts, lists:
http://hmgforum.com/viewtopic.php?p=53811#p53811
and also for trees:
http://hmgforum.com/viewtopic.php?p=57440#p57440

Here is the latest version:
DragAndDrop_0.007.zip
(18.42 KiB) Downloaded 128 times
Added two functions:
HMG_DaD_DragControlEnable( cDragFromForm, cDragFromControl, lEnabled )
HMG_DaD_DropControlEnable( cDropToForm, cDropToControl, lEnabled)
User avatar
bpd2000
Posts: 1207
Joined: Sat Sep 10, 2011 4:07 am
Location: India

Re: copy items from a loaded grid to another grid or virtual grid

Post by bpd2000 »

jairpinho wrote: Tue Nov 10, 2020 11:48 pm
edk wrote: Tue Nov 10, 2020 10:41 pm Maybe this will be useful:
(simplified version without error handling)
EDK, thank you what you were looking for how to do
+1
Who will update on Github
BPD
Convert Dream into Reality through HMG
User avatar
jairpinho
Posts: 420
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Contact:

Re: copy items from a loaded grid to another grid or virtual grid

Post by jairpinho »

hello because the load window with variable passed by parameter doesn't work

Code: Select all

***********************************
Function CloneGrid(oForm_1,oGrid_1,oForm_2,oGrid_2)
Local i

PRIVATE oForm1  := oForm_1     //
PRIVATE oGrid1  := oGrid_1     //
PRIVATE oForm2  := oForm_2     //
PRIVATE oGrid2  := oGrid_2     //


DECLARE WINDOW &oForm1.
DECLARE WINDOW &oForm2.
DECLARE &oGrid1.
DECLARE &oGrid2.

        Load Window oForm_2



//&oForm_1.vartostr(&oGrid_1).DeleteAllItems
FOR i = 1 TO &oForm1..&oGrid1..ItemCount
	&oForm2..&oGrid2..AddItem ( HMG_GetGridRowItems ( oForm_1, oGrid_1, i ) )
NEXT i

        &oForm2..Center
        &oForm2..Activate

RETURN
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br
Post Reply