block cells in a grid at runtime

Topic Specific Tutorials and Tips.

Moderator: Rathinagiri

Post Reply
User avatar
luisvasquezcl
Posts: 1077
Joined: Thu Jul 31, 2008 3:23 am
Location: Chile
Has thanked: 12 times
Been thanked: 14 times
Contact:

block cells in a grid at runtime

Post by luisvasquezcl » Wed Dec 12, 2012 2:22 pm

Hola a todos,
La función indicada a continuación permite bloquear o desbloquear una celda ( o las que quiera ) de un grid para su edición.
Normalmente podemos bloquear la edición de las celdas en tiempo de diseño completando la propiedad ColumnWhen.
Con este procedimiento obtengo el array que contiene la definicion de la propiedad ColumnWhen del grid y simplemente cambio el bloque de código definido para la columna de acuerdo a la condición que se desee.
Para que funcione el bloqueo antes de que se edite yo lo puse en el evento On Change del Grid por lo tanto cada vez que navego por las filas del grid me cambia el estado automáticamente de acuerdo a la condición que espero se cumpla.

En este ejemplo tengo un grid con 3 datos que son Id, Rut, Nombre. y verifico que si la celda ID está en 0 el usuario puede ingresar datos en la celda Rut en caso contrario no permite hacerlo, solo la celda Nombre.

static procedure lock_cell
local i := GetControlIndex ( "grid_1" , "Form_1" )
_HMG_SYSDATA[ 40 ] [ i ] [ 6 ] [ 2 ] := if( form_1.grid_1.cell(form_1.grid_1.value,1 ) <> 0, { || .f. } , { || .t. } )
return

Espero les sea de utilidad
Saludos cordiales,
Luis Vasquez

English By Google Translator

Hi all,
The function shown below to lock or unlock a cell (or want) a grid for editing.
Normally we can block cell editing at design time completing ColumnWhen property.
With this procedure I get an array that contains the definition of the grid ColumnWhen property and simply change the code block defined for the column according to the desired condition.
To operate the lock releases before I put it in the Grid On Change event so every time I browse the rows of the grid changes my status automatically according to the condition that hope is fulfilled.

In this example I have a grid with 3 data are Id, Ruth, Name. and verify that if the cell ID is 0 the user can enter data in cell Rut otherwise not allowed to do so, only the cell name.

static procedure lock_cell
local i := GetControlIndex ( "grid_1" , "Form_1" )
_HMG_SYSDATA[ 40 ] [ i ] [ 6 ] [ 2 ] := if( form_1.grid_1.cell(form_1.grid_1.value,1 ) <> 0, { || .f. } , { || .t. } )
return


I hope this will be useful
Best regards,
Luis Vasquez

User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil
Has thanked: 100 times
Been thanked: 179 times

Post by Pablo César » Wed Dec 12, 2012 3:57 pm

Gracias Luis por compartir con nosotros. Muy buena solucion !
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein

User avatar
Rathinagiri
Posts: 5210
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 155 times
Been thanked: 144 times
Contact:

Post by Rathinagiri » Wed Dec 12, 2012 4:08 pm

Thanks a lot!
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

User avatar
srvet_claudio
Posts: 2016
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Has thanked: 34 times
Been thanked: 143 times
Contact:

Post by srvet_claudio » Thu Dec 13, 2012 12:15 pm

Hola Luis.
Podés cambiar en tiempo de ejecución cualquier control de edición de un Grid con GridEx de la librería HFCL.

Code: Select all

// FUNCTIONS
**********************************************************************************
* GRID_ColumnCount         ---> Return the Number of Column on GRID
*
* GRID_AddColumnEx         ---> Complement of Method:  AddColumn (nColIndex)
* GRID_DeleteColumnEx      ---> Complement of Method:  DeleteColumn (nColIndex)
*
* GRID_GetColumnControlsEx ---> Return Array with Controls of Column(nColIndex) ==> {cCAPTION, nWIDTH, nJUSTIFY, aCOLUMNCONTROL, bDYNAMICBACKCOLOR, bDYNAMICFORECOLOR, bCOLUMNWHEN, bCOLUMNVALID, bONHEADCLICK}
*
* GRID_GetColumnControl    ---> Return specific Control of Column(nColIndex) ==> [cCAPTION, nWIDTH, nJUSTIFY, aCOLUMNCONTROL, bDYNAMICBACKCOLOR, bDYNAMICFORECOLOR, bCOLUMNWHEN, bCOLUMNVALID, bONHEADCLICK]

* GRID_SetColumnControl    ---> Set specific Control of Column(nColIndex)    ==> [cCAPTION, nWIDTH, nJUSTIFY, aCOLUMNCONTROL, bDYNAMICBACKCOLOR, bDYNAMICFORECOLOR, bCOLUMNWHEN, bCOLUMNVALID, bONHEADCLICK]
*
* GRID_GetColumnDisplayPos ---> Get the position of Column(nColIndex) in that display in the GRID
* GRID_SetColumnDisplayPos ---> Set the position of Column(nColIndex) in that display in the GRID
*
* GRID_GetColumnWidthDisplay -> Get the Width of Column(nColIndex) in that display in the GRID
*
* GRID_SetBkImage          ---> Set background image in Grid
**********************************************************************************


// SYNTAX
**********************************************************************************
* GRID_ColumnCount (cControlName , [cParentForm])
* GRID_AddColumnEx (cControlName, [cParentForm], nColIndex, [aCOLUMNCONTROL], [bDYNAMICBACKCOLOR], [bDYNAMICFORECOLOR], [bCOLUMNWHEN], [bCOLUMNVALID], [bONHEADCLICK])
* GRID_DeleteColumnEx (cControlName, [cParentForm], nColIndex)
* GRID_GetColumnControlsEx (cControlName, [cParentForm], nColIndex)
* GRID_GetColumnControl (cControlName , [cParentForm], nControl, nColIndex)
* GRID_SetColumnControl (cControlName , [cParentForm], nControl, nColIndex, Data)
* GRID_GetColumnDisplayPos (cControlName, [cParentForm], nColIndex)
* GRID_SetColumnDisplayPos (cControlName, [cParentForm], nColIndex, nPos_Display)
* GRID_GetColumnWidthDisplay (cControlName, cParentForm, nColIndex)
* GRID_SetBkImage (cControlName, [cParentForm], nAction, cBMPFileName, yOffset, xOffset)
**********************************************************************************
Fíjate el ejemplo en C:\hmg.3.1.1\hfcl\Samples\GridEx
Un abrazo,
Claudio.
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com

User avatar
luisvasquezcl
Posts: 1077
Joined: Thu Jul 31, 2008 3:23 am
Location: Chile
Has thanked: 12 times
Been thanked: 14 times
Contact:

Post by luisvasquezcl » Thu Dec 13, 2012 6:31 pm

Gracias Claudio por la aclaración.
Tendré que darle una mirada al manual ;)
Saludos cordiales,
Luis Vasquez

Leopoldo Blancas
Posts: 344
Joined: Wed Nov 21, 2012 7:14 pm
Location: México
Has thanked: 1 time
Been thanked: 4 times

Post by Leopoldo Blancas » Wed Dec 19, 2012 4:09 am

Hello

It only take a look at the sample executables that come in HFCL, and truly extraordinary, thank you for your time and dedication to Dr. Claudio HMG:!:
Greetings from Mexico
Polo


*-----------------------------------------------------------------------------------------------------------------------------
Hola

Solo le heche un vistazo a los ejecutables que vienen de ejemplo en HFCL, y en verdad extraordinarios, mil gracias por su tiempo y dedicación a HMG Dr. Claudio :!:
Saludos desde México
Polo

User avatar
srvet_claudio
Posts: 2016
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Has thanked: 34 times
Been thanked: 143 times
Contact:

Post by srvet_claudio » Wed Dec 19, 2012 10:37 am

Leopoldo Blancas wrote:Hello

It only take a look at the sample executables that come in HFCL, and truly extraordinary, thank you for your time and dedication to Dr. Claudio HMG:!:
Greetings from Mexico
Polo


*-----------------------------------------------------------------------------------------------------------------------------
Hola

Solo le heche un vistazo a los ejecutables que vienen de ejemplo en HFCL, y en verdad extraordinarios, mil gracias por su tiempo y dedicación a HMG Dr. Claudio :!:
Saludos desde México
Polo
Polo, muchas gracias.
Saludos,
Claudio.
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com

User avatar
giuper63
Posts: 10
Joined: Wed Oct 17, 2012 10:40 pm
DBs Used: DBF, mysql, sqlite, PostgresSQL
Location: Montecassiano
Contact:

Post by giuper63 » Fri Jan 18, 2013 11:15 pm

Many thanks Claudio,
your post helped me very much to find the column width not only in grid but also in browse columns!

Great!
Greetings.
Giuseppe
Italian developer

User avatar
srvet_claudio
Posts: 2016
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Has thanked: 34 times
Been thanked: 143 times
Contact:

Post by srvet_claudio » Fri Jan 18, 2013 11:31 pm

giuper63 wrote:Many thanks Claudio,
your post helped me very much to find the column width not only in grid but also in browse columns!

Great!
Greetings.
Thanks Giuseppe.
Regards,
Claudio.
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com

Post Reply