virtual grid + grid_edit

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
mlnr
Posts: 129
Joined: Fri Aug 28, 2015 1:52 pm
DBs Used: DBF

virtual grid + grid_edit

Post by mlnr »

Hi,

I would like to use the virtual grid and and the grid_edit together, but when i change a cell value, it doesn't modify to the new value.
Is this possible at all?

(It works in general grid without virtual.)

Code: Select all

#include "hmg.ch"

Function Main

public aRows [21] [3]

   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'} 
   aRows [21]   := {'Fernández','two','0000-0000'} 

   FOR i = 1 TO 21
     AADD (aRows[i],str(i))
   NEXT

   DEFINE WINDOW Form_1 ;
      AT 0,0 ;
      WIDTH 800 ;
      HEIGHT 650 ;
      TITLE "CELLNAVIGATION";
      MAIN 

      @ 10,10 GRID Grid_1 ;
         WIDTH 760 ;
         HEIGHT 590 ;
         HEADERS {'Last Name','First Name','Phone',"Num"} ;
         WIDTHS {140,140,140,50};
         ITEMS aRows ;
         VALUE 1;
         EDIT;
         VIRTUAL;                              //works if you delete this line
         ON QueryData QueryTest(); 
         CELLNAVIGATION;
         EDITOPTION GRID_EDIT_REPLACEALL

         Form_1.Grid_1.ColumnCONTROL (4) := {"TEXTBOX", "NUMERIC",NIL,NIL}
         Form_1.Grid_1.ColumnJUSTIFY (4) := GRID_JTFY_RIGHT

   END WINDOW

   CENTER WINDOW Form_1

   ACTIVATE WINDOW Form_1

Return

function QueryTest()
   local i := this.queryrowindex
   local j := this.querycolindex
   this.querydata := aRows[ i, j ]
return nil
edk
Posts: 999
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: virtual grid + grid_edit

Post by edk »

Szia Gábor.
Vessen egy pillantást erre a megoldásra:

Code: Select all

#include "hmg.ch"

Function Main

public aRows [21] [3]

   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'} 
   aRows [21]   := {'Fernández','two','0000-0000'} 

   FOR i = 1 TO 21
     AADD (aRows[i],str(i))
   NEXT

   DEFINE WINDOW Form_1 ;
      AT 0,0 ;
      WIDTH 800 ;
      HEIGHT 650 ;
      TITLE "CELLNAVIGATION";
      MAIN 

      @ 10,10 GRID Grid_1 ;
         WIDTH 760 ;
         HEIGHT 590 ;
         HEADERS {'Last Name','First Name','Phone',"Num"} ;
         WIDTHS {140,140,140,50};
         ITEMS aRows ;
         VALUE 1;
         EDIT;
         COLUMNVALID { { || ChangeGrigCell() } , { || ChangeGrigCell() } , { || ChangeGrigCell() } , { || ChangeGrigCell() } } ;
         VIRTUAL;                              //works if you delete this line
         ON QueryData QueryTest(); 
         CELLNAVIGATION;
         EDITOPTION GRID_EDIT_REPLACEALL

         Form_1.Grid_1.ColumnCONTROL (4) := {"TEXTBOX", "NUMERIC",NIL,NIL}
         Form_1.Grid_1.ColumnJUSTIFY (4) := GRID_JTFY_RIGHT

   END WINDOW

   CENTER WINDOW Form_1

   ACTIVATE WINDOW Form_1

Return

function QueryTest()
   local i := this.queryrowindex
   local j := this.querycolindex
   this.querydata := aRows[ i, j ]
return nil

Function ChangeGrigCell()
Local nRow := This.CellRowIndex, nCol := This.CellColIndex
Local xValue := This.CellValue

//you can manipulate and/or check values of cells

//Store cell value into an array
aRows [ nRow ] [ nCol ] := xValue
RETURN .T.
mlnr
Posts: 129
Joined: Fri Aug 28, 2015 1:52 pm
DBs Used: DBF

Re: virtual grid + grid_edit

Post by mlnr »

Dzień dobry Edward, :)

Thank you very much.
Simple and very nice solution.
Post Reply