All grid values to md array

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

User avatar
Claudio Ricardo
Posts: 367
Joined: Tue Oct 27, 2020 3:38 am
DBs Used: DBF, MySQL, MariaDB
Location: Bs. As. - Argentina

All grid values to md array

Post 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 !!!
Corrige al sabio y lo harás más sabio, Corrige al necio y lo harás tu enemigo.
WhatsApp / Telegram: +54 911-63016162
franco
Posts: 921
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: All grid values to md array

Post by franco »

Second question.

ColumnWhen { || {.F.} , { .F.} , {.F.} ,{.F.}, {.T.} } // 5 columns.. Last one can edit.
AllowEdit .T.
All The Best,
Franco
Canada
User avatar
Claudio Ricardo
Posts: 367
Joined: Tue Oct 27, 2020 3:38 am
DBs Used: DBF, MySQL, MariaDB
Location: Bs. As. - Argentina

Re: All grid values to md array

Post 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:
Attachments
Demo.zip
(1.43 MiB) Downloaded 91 times
Corrige al sabio y lo harás más sabio, Corrige al necio y lo harás tu enemigo.
WhatsApp / Telegram: +54 911-63016162
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: All grid values to md array

Post 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. } }
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
AUGE_OHR
Posts: 2117
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: All grid values to md array

Post 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 ?
have fun
Jimmy
User avatar
Claudio Ricardo
Posts: 367
Joined: Tue Oct 27, 2020 3:38 am
DBs Used: DBF, MySQL, MariaDB
Location: Bs. As. - Argentina

Re: All grid values to md array

Post by Claudio Ricardo »

Hola Andy, tu codeblock funcionó perfecto !!! Muchisimas Gracias !!!
Corrige al sabio y lo harás más sabio, Corrige al necio y lo harás tu enemigo.
WhatsApp / Telegram: +54 911-63016162
User avatar
Claudio Ricardo
Posts: 367
Joined: Tue Oct 27, 2020 3:38 am
DBs Used: DBF, MySQL, MariaDB
Location: Bs. As. - Argentina

Re: All grid values to md array

Post 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.
Corrige al sabio y lo harás más sabio, Corrige al necio y lo harás tu enemigo.
WhatsApp / Telegram: +54 911-63016162
franco
Posts: 921
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: All grid values to md array

Post by franco »

Sorry Claudio, for my miss advice.
All The Best,
Franco
Canada
User avatar
AUGE_OHR
Posts: 2117
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: All grid values to md array

Post 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
have fun
Jimmy
User avatar
SALINETAS24
Posts: 667
Joined: Tue Feb 27, 2018 3:06 am
DBs Used: DBF
Contact:

Re: All grid values to md array

Post 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 !!!!.
Attachments
Demo.rar
(1.21 MiB) Downloaded 77 times
Como dijo el gran pensador Hommer Simpson..., - En este mundo solo hay 3 tipos de personas, los que saben contar y los que no. :shock:
Post Reply