DRAG GRID in the same grid
Posted: Thu Jun 17, 2021 12:04 pm
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.
Exclusive forum for HMG, a Free / Open Source xBase WIN32/64 Bits / GUI Development System
http://mail.hmgforum.com/
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 positioningandyglezl 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.
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
Code: Select all
1.0
2.0
2.1
3.0
4.0
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
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 wrote: ↑Fri Jun 18, 2021 10:02 pmSo 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- 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 wrote: ↑Fri Jun 18, 2021 10:02 pmSo 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- 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
Code: Select all
ADD ITEM aCol TO Grid_2 OF Form_Novo_projeto
oQuery:Skip(1)
Next
Code: Select all
AADD (aItems, aCol)
oQuery:Skip(1)
Next
Form_Novo_projeto.Grid_2.ItemCount := Len ( aItems )
Form_Novo_projeto.Grid_2.Refresh