GRID control
Moderator: Rathinagiri
GRID control
Is it possible to determine the fields to diplay at runtime in a gridcontrol?
Re: GRID control
SPANISH:t57042 wrote:Is it possible to determine the fields to diplay at runtime in a gridcontrol?
Sí, ya que al GRID le puedes indicar el nombre del array sin que sea necesario pasarle el array definido en el tiempo de diseño.
Por lo tanto tienes por lo menos dos formas:
a) [ ITEMS <acItems> ]
Puedes llenar acItems en el momento que tu quieras, por ejemplo ON INIT
b) [ COLUMNFIELDS <acColumnFields> ]
Estas columnas (acColumnFields) tienen su origen desde la DBF que indiques en [ ROWSOURCE <cRowSource>]
ENGLISH:
Yes, because the GRID you can indicate the name of the array without having to pass the array defined in design time.
Therefore you have at least two ways:
a) [<acItems> ITEMS]
Please fill acItems when you want, for example ON INIT
b) [COLUMNFIELDS <acColumnFields>]
These columns (acColumnFields) originate from the DBF to indicate in [ROWSOURCE <cRowSource>]
Saludos, Fernando Chirico.
Re: GRID control
Hay un ejemplo en los samples?
- Rathinagiri
- Posts: 5471
- Joined: Tue Jul 29, 2008 6:30 pm
- DBs Used: MariaDB, SQLite, SQLCipher and MySQL
- Location: Sivakasi, India
- Contact:
Re: GRID control
Had you seen the samples from c:\hmg\samples\
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
South or North HMG is worth.
...the possibilities are endless.
Re: GRID control
Indeed, and I don't find any example where the colums are determined after vreation of the grid.
- srvet_claudio
- Posts: 2193
- Joined: Thu Feb 25, 2010 8:43 pm
- Location: Uruguay
- Contact:
Re: GRID control
Aparentemente los campos de los grid con base de datos ( COLUMNFIELDS y otros) solo se pueden especificar en tiempo de diseño no en tiempo de ejecución.t57042 wrote:Is it possible to determine the fields to diplay at runtime in a gridcontrol?
Una forma que se me ocurrió fue cada vez que necesites cambiar los campos en la visualizacion del grid, este se destruya (ventana.grid_1.release) y se vuelva a crear con los campos que necesites visualizar en ese momento. Si bien esto funciona tiene el inconveniente que con bases de datos muy grandes tal vez la rutina de revisualización puede quedar algo lento.
A continuación te dejo un ejemplo que modifique de \SAMPLES\GRID.25 de HMG 3.0.26
Code: Select all
/*
* MiniGUI Virtual Grid Demo
* (c) 2009 Roberto Lopez
*/
#include "hmg.ch"
Function Main
Local aValue := { Nil , Nil }
* Grid Column Controls Definitions
aCtrl_1 := {'TEXTBOX','NUMERIC','9999999999'}
aCtrl_2 := {'TEXTBOX','CHARACTER'}
aCtrl_3 := {'TEXTBOX','CHARACTER'}
aCtrl_4 := {'DATEPICKER','UPDOWN'}
aCtrl_5 := { 'CHECKBOX' , 'Yes' , 'No' }
aCtrl_6 := { 'EDITBOX' }
mat_HEADERS_todos :={'Column 1','Column 2','Column 3','Column 4','Column 5','Column 6'}
mat_WIDTHS_todos :={140,140,140,100,100,100}
mat_COLUMNCONTROLS_todos :={ aCtrl_1 , aCtrl_2 , aCtrl_3 , aCtrl_4 , aCtrl_5 , aCtrl_6 }
mat_COLUMNFIELDS_todos :={ 'Code' , 'First' , 'Last' , 'Birth' , 'Married' , 'Bio' }
mat_HEADERS := mat_HEADERS_todos
mat_WIDTHS := mat_WIDTHS_todos
mat_COLUMNCONTROLS := mat_COLUMNCONTROLS_todos
mat_COLUMNFIELDS := mat_COLUMNFIELDS_todos
DEFINE WINDOW Form_1 ;
AT 0,0 ;
WIDTH 800 ;
HEIGHT 510 ;
TITLE 'Hello World!' ;
MAIN
DEFINE MAIN MENU
POPUP 'File'
ITEM 'Pack' ACTION Pack()
ITEM 'Append (Alt+A)' ACTION Form_1.Grid_1.Append
ITEM 'Set RecNo' ACTION Form_1.Grid_1.RecNo := val(InputBox('',''))
ITEM 'Get RecNo' ACTION MsgInfo( Str(Form_1.Grid_1.RecNo) )
ITEM 'Delete (Alt+D)' ACTION Form_1.Grid_1.Delete
ITEM 'Recall (Alt+R)' ACTION Form_1.Grid_1.Recall
ITEM 'Get Value' ACTION ( aValue := Form_1.Grid_1.Value , MsgInfo( Str( aValue [1] ) + ' , ' + Str( aValue [2] ) ) )
ITEM 'Set Value' ACTION ( aValue [ 1 ] := val(InputBox('New Row','Selected Cell (Value)')) , aValue [ 2 ] := val(InputBox('New Col','Selected Cell (Value)')) , Form_1.Grid_1.Value := { aValue [ 1 ] , aValue [ 2 ] } )
ITEM 'Save Pending Changes (Alt+S)' ACTION Form_1.Grid_1.Save
ITEM 'Clear Changes Buffer (Undo) (ALt+U)' ACTION Form_1.Grid_1.ClearBuffer
END POPUP
POPUP 'FIELDS'
ITEM 'Ver Todos' ACTION cambiar_field (1)
ITEM 'Ver FIELDS 1, 2 y 3' ACTION cambiar_field (2)
ITEM 'Ver FIELDS 4, 5 y 6' ACTION cambiar_field (3)
END POPUP
END MENU
USE TEST // SHARED
INDEX ON CODE TO CODE
*PACK
GO TOP
@ 10,10 GRID Grid_1 ;
WIDTH 770 ;
HEIGHT 440 ;
HEADERS mat_HEADERS;
WIDTHS mat_WIDTHS;
EDIT ;
VALUE { 1 , 1 } ;
COLUMNCONTROLS mat_COLUMNCONTROLS;
ROWSOURCE "Test" ;
COLUMNFIELDS mat_COLUMNFIELDS;
ALLOWAPPEND ;
ALLOWDELETE
END WINDOW
CENTER WINDOW Form_1
ACTIVATE WINDOW Form_1
Return
Function pack
pack
Form_1.Grid_1.Refresh
Return
procedure cambiar_field (n)
mat_HEADERS := {}
mat_WIDTHS := {}
mat_COLUMNCONTROLS := {}
mat_COLUMNFIELDS := {}
do case
case n = 1
mat_HEADERS := mat_HEADERS_todos
mat_WIDTHS := mat_WIDTHS_todos
mat_COLUMNCONTROLS := mat_COLUMNCONTROLS_todos
mat_COLUMNFIELDS := mat_COLUMNFIELDS_todos
case n = 2
for i = 1 to 3
aadd (mat_HEADERS, mat_HEADERS_todos [i])
aadd (mat_WIDTHS, mat_WIDTHS_todos [i])
aadd (mat_COLUMNCONTROLS, mat_COLUMNCONTROLS_todos [i])
aadd (mat_COLUMNFIELDS, mat_COLUMNFIELDS_todos[i])
next
case n = 3
for i = 4 to 6
aadd (mat_HEADERS, mat_HEADERS_todos [i])
aadd (mat_WIDTHS, mat_WIDTHS_todos [i])
aadd (mat_COLUMNCONTROLS, mat_COLUMNCONTROLS_todos [i])
aadd (mat_COLUMNFIELDS, mat_COLUMNFIELDS_todos[i])
next
endcase
reg := 1
IF IsControlDefined ( Grid_1 , Form_1 )
reg := Form_1.Grid_1.recno
Form_1.Grid_1.Release
ENDIF
@ 10,10 GRID Grid_1 OF Form_1;
WIDTH 770 ;
HEIGHT 440 ;
HEADERS mat_HEADERS;
WIDTHS mat_WIDTHS;
EDIT ;
VALUE { reg , 1 } ;
COLUMNCONTROLS mat_COLUMNCONTROLS;
ROWSOURCE "Test" ;
COLUMNFIELDS mat_COLUMNFIELDS;
ALLOWAPPEND ;
ALLOWDELETE
return
Claudio Soto
Re: GRID control
Muchas gracias
- Pablo César
- Posts: 4059
- Joined: Wed Sep 08, 2010 1:18 pm
- Location: Curitiba - Brasil
GRID control
Fantástico, esta alternativa me ayudó mucho. Muchas gracias Dr. Claudio !srvet_claudio wrote:Aparentemente los campos de los grid con base de datos ( COLUMNFIELDS y otros) solo se pueden especificar en tiempo de diseño no en tiempo de ejecución.
Una forma que se me ocurrió fue cada vez que necesites cambiar los campos en la visualizacion del grid, este se destruya (ventana.grid_1.release) y se vuelva a crear con los campos que necesites visualizar en ese momento.
..//..
A continuación te dejo un ejemplo que modifique de \SAMPLES\GRID.25 de HMG 3.0.26
--- Translated to English:
Great alternative solution, this really helped me much. Thank you very much, Dr. Claudio !
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
-
- Posts: 388
- Joined: Wed Nov 21, 2012 7:14 pm
- Location: México
Re: GRID control
Excelente Dr. Claudio.... Muy bien....
Saludos
Polo
Saludos
Polo