Page 1 of 2

All grid values to md array

Posted: Mon Feb 07, 2022 6:53 pm
by Claudio Ricardo
Hola, Tengo un grid que recibe datos desde array, resultados de cálculos y además se pueden editar celdas...
Una vez terminada la edición, quiero todos esos datos en un array multidimensional para primero
validarlos (tipo, rango, len, etc.) si hace falta modificarlos, sinó guardarlos desde ese array.
La primera pregunta es: Tengo que hacer un bucle y leer celda por celda todo el grid creando el array,
o hay un modo más " directo " ? Tal vez en _HMG_SYSDATA ?
La segunda es: Quiero que sólo una columna del grid sea editable, cómo seteo esa propiedad ?
Desde yá muchas gracias !!!

English from Google translator :oops:
Hello, I have a grid that receives data from an array, calculation results and also cells can be edited...
Once the editing is done, I want all that data in a multidimensional array for first
validate them (type, range, len, etc.) if it is necessary to modify them, but save them from that array.
The first question is: I have to make a loop and read cell by cell the entire grid creating the array,
or is there a more "direct" way? Maybe in _HMG_SYSDATA ?
The second is: I want only one column of the grid to be editable, how do I set that property?
From already thank you very much !!!

Re: All grid values to md array

Posted: Mon Feb 07, 2022 10:22 pm
by franco
Second question.

ColumnWhen { || {.F.} , { .F.} , {.F.} ,{.F.}, {.T.} } // 5 columns.. Last one can edit.
AllowEdit .T.

Re: All grid values to md array

Posted: Tue Feb 08, 2022 1:44 am
by Claudio Ricardo
Thank you very much Franco, but it didn't work for me with that code block, I can still edit all the columns :cry:
I still have a lot to learn about the grid control :oops:

Re: All grid values to md array

Posted: Tue Feb 08, 2022 3:16 am
by andyglezl
franco wrote: Mon Feb 07, 2022 10:22 pm Second question.

ColumnWhen { || {.F.} , { .F.} , {.F.} ,{.F.}, {.T.} } // 5 columns.. Last one can edit.
AllowEdit .T.

COLUMNWHEN { { || .F. }, { || .F. }, { || .F. }, { || .F. }, { || .T. } }

Re: All grid values to md array

Posted: Tue Feb 08, 2022 5:05 am
by AUGE_OHR
hi Claudio,
Claudio Ricardo wrote: Mon Feb 07, 2022 6:53 pm I have a grid that receives data from an array
when you use a Array (or Result-Set) for GRID i do "manipulate" Array not GRID where i do "refresh" only.

---

i saw "Port 3306"
did you want to work with MySQL ?

Re: All grid values to md array

Posted: Tue Feb 08, 2022 1:07 pm
by Claudio Ricardo
Hola Andy, tu codeblock funcionó perfecto !!! Muchisimas Gracias !!!

Re: All grid values to md array

Posted: Tue Feb 08, 2022 1:59 pm
by Claudio Ricardo
Hi Jimmy, I load the grid with fixed values from an array, but the fourth column contains a percentage that sometimes changes in some record, that's why the user must be able to edit only that column (achieved thanks to Andy's codeblock) and when "enter" is pressed, the new result is displayed in the fifth column, overwriting the previous one, when the user finishes editing and presses the save button, I need to read the values that remained in the grid (different from the array with which I loaded the grid) in another array to add them, validate them and save them.
I can make a loop and read cell by cell creating the new array (which I compare with the previous one and calculate the difference) but I thought that there is a way for the grid to acquire its content.

Yes, I work with SQL and MariaDb although the prg I uploaded is just a dummy made to test these things on a grid before incorporating them into the real program.

Re: All grid values to md array

Posted: Tue Feb 08, 2022 5:42 pm
by franco
Sorry Claudio, for my miss advice.

Re: All grid values to md array

Posted: Tue Feb 08, 2022 8:39 pm
by AUGE_OHR
hi Claudio,

perhaps i´m wrong ... just run you Demo and what i "saw"
you are using a "fixed" Array for GRID

Code: Select all

   ITEMS { {"","","","",""} }
it can also be a Variable

Code: Select all

   ITEMS aData
so when a Cell is change

Code: Select all

   ALLOWEDIT .T.
it is the Array in Background :!:

---

but your Demo is limited on 1 x ROW

when use

Code: Select all

   VIRTUAL .T.
you also need

Code: Select all

   ONQUERYDATA MySkipper(aData)
and

Code: Select all

   ITEMCOUNT LEN( aData )

Code: Select all

FUNCTION MySkipper(aData)   
LOCAL nRow := This.QueryRowIndex
LOCAL nCol := This.Querycolindex
LOCAL xVal

   IF .NOT. EMPTY( nRow ) .AND. LEN( aData ) >= nRow
      xVal := aData[ nRow ] [ nCol ]
      This.QueryData := xVal
   ENDIF
RETURN .T.
---

when "add" new ROW you need

Code: Select all

   AADD(aData, NewData)
   SetProperty( "Main", "Grid_1", "ITEMCOUNT", LEN( aData ) )
before "refresh" GRID

Code: Select all

   DoMethod( "Main", "Grid_1", "Refresh" )
hope that was what you asking for

Re: All grid values to md array

Posted: Tue Feb 08, 2022 10:05 pm
by SALINETAS24
Claudio Ricardo wrote: Mon Feb 07, 2022 6:53 pm Hola, Tengo un grid que recibe datos desde array, resultados de cálculos y además se pueden editar celdas...
Una vez terminada la edición, quiero todos esos datos en un array multidimensional para primero
validarlos (tipo, rango, len, etc......
Hola Claudio, he modificado un poco tu ejemplo para que veas una posible solución con un GRID VITUAL.
Espero que te pueda orientar.

Salud y cervecita fresquita !!!!.