DRAG GRID in the same grid

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

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

DRAG GRID in the same grid

Post by jairpinho »

hello, if there is the DRAGITEMS property in a grid?, if there is no way I can move the lines of a grid in position.
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br
User avatar
jairpinho
Posts: 420
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Contact:

Re: DRAG GRID in the same grid

Post by jairpinho »

hello, temporary solution would be how could you move a selected row up and down in the grid using buttons
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: DRAG GRID in the same grid

Post by andyglezl »

Solo una idea...
Porque no añades una columna en donde pongas el orden en que los quiere:
1
5
3
2
7
9
Y al darle click en el encabezado, ordenas el grid.
*-------------------------------------------------------------------------------------------------
Just an idea ...
Why don't you add a column where you put the order in which you want them:
1
5
3
2
7
9
And when you click on the header, you order the grid.
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
jairpinho
Posts: 420
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Contact:

Re: DRAG GRID in the same grid

Post by jairpinho »

andyglezl wrote: Fri Jun 18, 2021 3:49 pm Solo una idea...
Porque no añades una columna en donde pongas el orden en que los quiere:
1
5
3
2
7
9
Y al darle click en el encabezado, ordenas el grid.
*-------------------------------------------------------------------------------------------------
Just an idea ...
Why don't you add a column where you put the order in which you want them:
1
5
3
2
7
9
And when you click on the header, you order the grid.
hello Andres, I already have the item column but I need to change the order of this column at run time, moving it down or up, and it will be saved with a new order according to the new positioning
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br
User avatar
AUGE_OHR
Posts: 2060
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: DRAG GRID in the same grid

Post by AUGE_OHR »

hi,
jairpinho wrote: Fri Jun 18, 2021 4:28 pmI already have the item column but I need to change the order of this column at run time, moving it down or up, and it will be saved with a new order according to the new positioning
if you have a 2-Dim Array where 2nd Column are for Order : use Decimal to "insert" Item

Code: Select all

1
2
3
4
5
now move Item 5 behind 2

Code: Select all

1.0
2.0
2.1
3.0
4.0
---

did you know HMG_DaD* Function :idea:
Source of HMG_DaD* Function can be found in HMG IDE Source
http://hmgforum.com/viewtopic.php?p=64177#p64177

this Sample can DragDrop Item from upper GRID to empty GRID
GridDuo.zip
(11.94 KiB) Downloaded 48 times
Demo Sample also work with TREE and have TREEVIEW_HITTEST
but no ListView_HitTest() (from c:\hmg.3.4.4\SOURCE\c_grid.c )

LVHITTESTINFO Structure include Information "where" you "hit" to "insert" Item
https://docs.microsoft.com/en-us/window ... ittestinfo

---

Listview and Treeview work "same Way" so i guess it is possible to enhance Demo Sample.
i did it under Xbase++ using Ot4xb with my own native Control but not under HMG (yet)

p.s. you will get in build.log some Warning(s) ... :roll:
i do not know how to modify "C" Code in HB_FUNC.PRG to get rid of those Warning(s)
have fun
Jimmy
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: DRAG GRID in the same grid

Post by edk »

jairpinho wrote: Fri Jun 18, 2021 2:05 pm hello, temporary solution would be how could you move a selected row up and down in the grid using buttons
So fast with VIRTUAL GRID and Move Up and Move Down buttons. Unfortunately, I don't feel up to doing it in Drag And Drop yet :cry: - I'm sorry for that.

Code: Select all

#include "hmg.ch"

Function Main

Local aItems := {}

IF !File ('Items.Array')
	StrFile ( Hb_Serialize( {{'Simpson'  ,'Homer'    ,'555-5555'},;
		 					 {'Mulder'   ,'Fox'      ,'324-6432'},;
		 					 {'Smart'    ,'Max'      ,'432-5892'},; 
		 					 {'Grillo'   ,'Pepe'     ,'894-2332'},; 
		 					 {'Kirk'     ,'James'    ,'346-9873'},; 
		 					 {'Barriga'  ,'Carlos'   ,'394-9654'},; 
		 					 {'Flanders' ,'Ned'      ,'435-3211'},; 
		 					 {'Smith'    ,'John'     ,'123-1234'},; 
		 					 {'Pedemonti','Flavio'   ,'000-0000'},; 
		 					 {'Gomez'    ,'Juan'     ,'583-4832'},; 
		 					 {'Fernandez','Raul'     ,'321-4332'},; 
		 					 {'Borges'   ,'Javier'   ,'326-9430'},; 
		 					 {'Alvarez'  ,'Alberto'  ,'543-7898'},; 
		 					 {'Gonzalez' ,'Ambo'     ,'437-8473'},; 
		 					 {'Batistuta','Gol'      ,'485-2843'},; 
		 					 {'Vinazzi'  ,'Amigo'    ,'394-5983'},; 
		 					 {'Pedemonti','Flavio'   ,'534-7984'},; 
		 					 {'Samarbide','Armando'  ,'854-7873'},; 
		 					 {'Pradon'   ,'Alejandra','???-????'},; 
		 					 {'Reyes','Monica','432-5836'}} ), 'Items.Array' )
ENDIF

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

		DEFINE MAIN MENU
			DEFINE POPUP 'File'
				MENUITEM 'Load Items' ACTION ( aItems:= hb_DeSerialize ( FileStr ( 'Items.Array' ) ), Form_1.Grid_1.ItemCount := Len ( aItems ), Form_1.Grid_1.Refresh, MsgInfo ("Items Loaded"))
				MENUITEM 'Save Items' ACTION ( StrFile ( Hb_Serialize( aItems ), 'Items.Array' ), MsgInfo ("Items Saved"))
				MENUITEM 'Clear Items' ACTION ( aItems:= {}, Form_1.Grid_1.ItemCount := Len ( aItems ), Form_1.Grid_1.Refresh)
			END POPUP
		END MENU

		@ 10,10 GRID Grid_1 ;
		WIDTH 400 ;
		HEIGHT 330 ;
		HEADERS {'Last Name','First Name','Phone'} ;
		WIDTHS {140,140,90};
		VIRTUAL ;
		ITEMCOUNT Len ( aItems ) ;
		ON QUERYDATA QueryTest( aItems ) ; 
		CELLNAVIGATION ;
		VALUE { 1, 1 }
		
		@ 10, 440 BUTTON bUp   CAPTION "Move Up"   ACTION aItems := moveUp( aItems )   WIDTH 80
		@ 40, 440 BUTTON bDown CAPTION "Move Down" ACTION aItems := moveDown( aItems ) WIDTH 80
	END WINDOW

	CENTER WINDOW Form_1

	ACTIVATE WINDOW Form_1

Return

Procedure QueryTest( aItems )
Local i := This.QueryRowIndex
Local j := This.QueryColIndex

	This.QueryData := aItems [ i ] [ j ]

Return

Function moveUp( aItems )
Local nPos := Form_1.Grid_1.Value [ 1 ]
Local nCol := Form_1.Grid_1.Value [ 2 ]
Local aRow
IF Len ( aItems ) > 0 .AND. nPos > 1
	aRow := aItems [ nPos ]
	hb_ADel( aItems, nPos, .T. )
	hb_AIns( aItems, nPos - 1, aRow, .T. )
	Form_1.Grid_1.Refresh
	Form_1.Grid_1.Value := { nPos - 1, nCol }
ENDIF

RETURN aItems

Function moveDown( aItems )
Local nPos := Form_1.Grid_1.Value [ 1 ]
Local nCol := Form_1.Grid_1.Value [ 2 ]
Local aRow
IF Len ( aItems ) > 0 .AND. nPos < Len ( aItems )
	aRow := aItems [ nPos ]
	hb_ADel( aItems, nPos, .T. )
	hb_AIns( aItems, nPos + 1, aRow, .T. )
	Form_1.Grid_1.Refresh
	Form_1.Grid_1.Value := { nPos + 1, nCol }
ENDIF
RETURN aItems
User avatar
jairpinho
Posts: 420
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Contact:

Re: DRAG GRID in the same grid

Post by jairpinho »

edk wrote: Fri Jun 18, 2021 10:02 pm
jairpinho wrote: Fri Jun 18, 2021 2:05 pm hello, temporary solution would be how could you move a selected row up and down in the grid using buttons
So fast with VIRTUAL GRID and Move Up and Move Down buttons. Unfortunately, I don't feel up to doing it in Drag And Drop yet :cry: - I'm sorry for that.

Code: Select all

#include "hmg.ch"

Function Main

Local aItems := {}

IF !File ('Items.Array')
	StrFile ( Hb_Serialize( {{'Simpson'  ,'Homer'    ,'555-5555'},;
		 					 {'Mulder'   ,'Fox'      ,'324-6432'},;
		 					 {'Smart'    ,'Max'      ,'432-5892'},; 
		 					 {'Grillo'   ,'Pepe'     ,'894-2332'},; 
		 					 {'Kirk'     ,'James'    ,'346-9873'},; 
		 					 {'Barriga'  ,'Carlos'   ,'394-9654'},; 
		 					 {'Flanders' ,'Ned'      ,'435-3211'},; 
		 					 {'Smith'    ,'John'     ,'123-1234'},; 
		 					 {'Pedemonti','Flavio'   ,'000-0000'},; 
		 					 {'Gomez'    ,'Juan'     ,'583-4832'},; 
		 					 {'Fernandez','Raul'     ,'321-4332'},; 
		 					 {'Borges'   ,'Javier'   ,'326-9430'},; 
		 					 {'Alvarez'  ,'Alberto'  ,'543-7898'},; 
		 					 {'Gonzalez' ,'Ambo'     ,'437-8473'},; 
		 					 {'Batistuta','Gol'      ,'485-2843'},; 
		 					 {'Vinazzi'  ,'Amigo'    ,'394-5983'},; 
		 					 {'Pedemonti','Flavio'   ,'534-7984'},; 
		 					 {'Samarbide','Armando'  ,'854-7873'},; 
		 					 {'Pradon'   ,'Alejandra','???-????'},; 
		 					 {'Reyes','Monica','432-5836'}} ), 'Items.Array' )
ENDIF

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

		DEFINE MAIN MENU
			DEFINE POPUP 'File'
				MENUITEM 'Load Items' ACTION ( aItems:= hb_DeSerialize ( FileStr ( 'Items.Array' ) ), Form_1.Grid_1.ItemCount := Len ( aItems ), Form_1.Grid_1.Refresh, MsgInfo ("Items Loaded"))
				MENUITEM 'Save Items' ACTION ( StrFile ( Hb_Serialize( aItems ), 'Items.Array' ), MsgInfo ("Items Saved"))
				MENUITEM 'Clear Items' ACTION ( aItems:= {}, Form_1.Grid_1.ItemCount := Len ( aItems ), Form_1.Grid_1.Refresh)
			END POPUP
		END MENU

		@ 10,10 GRID Grid_1 ;
		WIDTH 400 ;
		HEIGHT 330 ;
		HEADERS {'Last Name','First Name','Phone'} ;
		WIDTHS {140,140,90};
		VIRTUAL ;
		ITEMCOUNT Len ( aItems ) ;
		ON QUERYDATA QueryTest( aItems ) ; 
		CELLNAVIGATION ;
		VALUE { 1, 1 }
		
		@ 10, 440 BUTTON bUp   CAPTION "Move Up"   ACTION aItems := moveUp( aItems )   WIDTH 80
		@ 40, 440 BUTTON bDown CAPTION "Move Down" ACTION aItems := moveDown( aItems ) WIDTH 80
	END WINDOW

	CENTER WINDOW Form_1

	ACTIVATE WINDOW Form_1

Return

Procedure QueryTest( aItems )
Local i := This.QueryRowIndex
Local j := This.QueryColIndex

	This.QueryData := aItems [ i ] [ j ]

Return

Function moveUp( aItems )
Local nPos := Form_1.Grid_1.Value [ 1 ]
Local nCol := Form_1.Grid_1.Value [ 2 ]
Local aRow
IF Len ( aItems ) > 0 .AND. nPos > 1
	aRow := aItems [ nPos ]
	hb_ADel( aItems, nPos, .T. )
	hb_AIns( aItems, nPos - 1, aRow, .T. )
	Form_1.Grid_1.Refresh
	Form_1.Grid_1.Value := { nPos - 1, nCol }
ENDIF

RETURN aItems

Function moveDown( aItems )
Local nPos := Form_1.Grid_1.Value [ 1 ]
Local nCol := Form_1.Grid_1.Value [ 2 ]
Local aRow
IF Len ( aItems ) > 0 .AND. nPos < Len ( aItems )
	aRow := aItems [ nPos ]
	hb_ADel( aItems, nPos, .T. )
	hb_AIns( aItems, nPos + 1, aRow, .T. )
	Form_1.Grid_1.Refresh
	Form_1.Grid_1.Value := { nPos + 1, nCol }
ENDIF
RETURN aItems

Edk thank you that's exactly what I needed right now
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br
User avatar
jairpinho
Posts: 420
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Contact:

Re: DRAG GRID in the same grid

Post by jairpinho »

edk wrote: Fri Jun 18, 2021 10:02 pm
jairpinho wrote: Fri Jun 18, 2021 2:05 pm hello, temporary solution would be how could you move a selected row up and down in the grid using buttons
So fast with VIRTUAL GRID and Move Up and Move Down buttons. Unfortunately, I don't feel up to doing it in Drag And Drop yet :cry: - I'm sorry for that.

Code: Select all

#include "hmg.ch"

Function Main

Local aItems := {}

IF !File ('Items.Array')
	StrFile ( Hb_Serialize( {{'Simpson'  ,'Homer'    ,'555-5555'},;
		 					 {'Mulder'   ,'Fox'      ,'324-6432'},;
		 					 {'Smart'    ,'Max'      ,'432-5892'},; 
		 					 {'Grillo'   ,'Pepe'     ,'894-2332'},; 
		 					 {'Kirk'     ,'James'    ,'346-9873'},; 
		 					 {'Barriga'  ,'Carlos'   ,'394-9654'},; 
		 					 {'Flanders' ,'Ned'      ,'435-3211'},; 
		 					 {'Smith'    ,'John'     ,'123-1234'},; 
		 					 {'Pedemonti','Flavio'   ,'000-0000'},; 
		 					 {'Gomez'    ,'Juan'     ,'583-4832'},; 
		 					 {'Fernandez','Raul'     ,'321-4332'},; 
		 					 {'Borges'   ,'Javier'   ,'326-9430'},; 
		 					 {'Alvarez'  ,'Alberto'  ,'543-7898'},; 
		 					 {'Gonzalez' ,'Ambo'     ,'437-8473'},; 
		 					 {'Batistuta','Gol'      ,'485-2843'},; 
		 					 {'Vinazzi'  ,'Amigo'    ,'394-5983'},; 
		 					 {'Pedemonti','Flavio'   ,'534-7984'},; 
		 					 {'Samarbide','Armando'  ,'854-7873'},; 
		 					 {'Pradon'   ,'Alejandra','???-????'},; 
		 					 {'Reyes','Monica','432-5836'}} ), 'Items.Array' )
ENDIF

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

		DEFINE MAIN MENU
			DEFINE POPUP 'File'
				MENUITEM 'Load Items' ACTION ( aItems:= hb_DeSerialize ( FileStr ( 'Items.Array' ) ), Form_1.Grid_1.ItemCount := Len ( aItems ), Form_1.Grid_1.Refresh, MsgInfo ("Items Loaded"))
				MENUITEM 'Save Items' ACTION ( StrFile ( Hb_Serialize( aItems ), 'Items.Array' ), MsgInfo ("Items Saved"))
				MENUITEM 'Clear Items' ACTION ( aItems:= {}, Form_1.Grid_1.ItemCount := Len ( aItems ), Form_1.Grid_1.Refresh)
			END POPUP
		END MENU

		@ 10,10 GRID Grid_1 ;
		WIDTH 400 ;
		HEIGHT 330 ;
		HEADERS {'Last Name','First Name','Phone'} ;
		WIDTHS {140,140,90};
		VIRTUAL ;
		ITEMCOUNT Len ( aItems ) ;
		ON QUERYDATA QueryTest( aItems ) ; 
		CELLNAVIGATION ;
		VALUE { 1, 1 }
		
		@ 10, 440 BUTTON bUp   CAPTION "Move Up"   ACTION aItems := moveUp( aItems )   WIDTH 80
		@ 40, 440 BUTTON bDown CAPTION "Move Down" ACTION aItems := moveDown( aItems ) WIDTH 80
	END WINDOW

	CENTER WINDOW Form_1

	ACTIVATE WINDOW Form_1

Return

Procedure QueryTest( aItems )
Local i := This.QueryRowIndex
Local j := This.QueryColIndex

	This.QueryData := aItems [ i ] [ j ]

Return

Function moveUp( aItems )
Local nPos := Form_1.Grid_1.Value [ 1 ]
Local nCol := Form_1.Grid_1.Value [ 2 ]
Local aRow
IF Len ( aItems ) > 0 .AND. nPos > 1
	aRow := aItems [ nPos ]
	hb_ADel( aItems, nPos, .T. )
	hb_AIns( aItems, nPos - 1, aRow, .T. )
	Form_1.Grid_1.Refresh
	Form_1.Grid_1.Value := { nPos - 1, nCol }
ENDIF

RETURN aItems

Function moveDown( aItems )
Local nPos := Form_1.Grid_1.Value [ 1 ]
Local nCol := Form_1.Grid_1.Value [ 2 ]
Local aRow
IF Len ( aItems ) > 0 .AND. nPos < Len ( aItems )
	aRow := aItems [ nPos ]
	hb_ADel( aItems, nPos, .T. )
	hb_AIns( aItems, nPos + 1, aRow, .T. )
	Form_1.Grid_1.Refresh
	Form_1.Grid_1.Value := { nPos + 1, nCol }
ENDIF
RETURN aItems


hello edk, I need to make this move without using virtual grid because I already loaded the normal grid with the command ADD ITEM aCol TO Grid_2 OF Form_Novo_projeto
For i:= 1 To oQuery:LastRec()

aCol[1] := cPrioridade
aCol[2] := cStatus
aCol[3] := Alltrim(STR(i))
aCol[4] := Alltrim(oRow:fieldGet(2) )
aCol[5] := Alltrim(oRow:fieldGet(3) )
aCol[6] := Alltrim(oRow:fieldGet(7) )
aCol[7] := PGENERIC( 1 , "descricao", "fabricantes" , "codigo" , Alltrim(oRow:fieldGet(5)) )
aCol[8] := Alltrim(oRow:fieldGet(4) )
aCol[9] := Alltrim(str(oRow:fieldGet(15) ) )
aCol[10] := Alltrim(str(oRow:fieldGet(16) ) )
aCol[11] := Alltrim(str(oRow:fieldGet(17) ) )
aCol[12] := DtoC((oRow:fieldGet(10) ))
aCol[13] := DtoC((oRow:fieldGet(11) ))
aCol[14] := DtoC((oRow:fieldGet(12) ))
aCol[15] := DtoC((oRow:fieldGet(13) ))
aCol[16] := DtoC((oRow:fieldGet(14) ))
aCol[17] := Alltrim(oRow:fieldGet(22) )
aCol[18] := Alltrim(STR(oRow:fieldGet(28)))
aCol[19] := PGENERIC( 1 , "nome", "fornecedores" , "codigo" , Alltrim(oRow:fieldGet(6)) )
aCol[20] := Alltrim(str(oRow:fieldGet(18) ) )
aCol[21] := Alltrim(STR(oRow:fieldGet(21)) )
aCol[22] := Alltrim(STR(oRow:fieldGet(20)))
aCol[23] := Alltrim(oRow:fieldGet(22))
aCol[24] := Alltrim(STR(oRow:fieldGet(1)))


ADD ITEM aCol TO Grid_2 OF Form_Novo_projeto
oQuery:Skip(1)
Next
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: DRAG GRID in the same grid

Post by edk »

IMHO regular GRID has limited ability to manipulate the order of items. You would have to remove all items and add again in a different order.

Better to use virtual and run directly on an array.

For virtual grid just change:

Code: Select all

ADD ITEM aCol TO Grid_2 OF Form_Novo_projeto
oQuery:Skip(1)
Next
to

Code: Select all

AADD (aItems, aCol)
oQuery:Skip(1)
Next
Form_Novo_projeto.Grid_2.ItemCount := Len ( aItems )
Form_Novo_projeto.Grid_2.Refresh

Post Reply