GRID control

Moderator: Rathinagiri

Post Reply
t57042
Posts: 148
Joined: Tue Mar 16, 2010 9:46 am
Location: belgium
Has thanked: 2 times
Been thanked: 4 times

GRID control

Post by t57042 » Fri Mar 26, 2010 1:48 pm

Is it possible to determine the fields to diplay at runtime in a gridcontrol?

User avatar
fchirico
Posts: 324
Joined: Sat Aug 23, 2008 11:27 pm
Location: Argentina

Post by fchirico » Fri Mar 26, 2010 2:27 pm

t57042 wrote:Is it possible to determine the fields to diplay at runtime in a gridcontrol?
SPANISH:
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.

t57042
Posts: 148
Joined: Tue Mar 16, 2010 9:46 am
Location: belgium
Has thanked: 2 times
Been thanked: 4 times

Post by t57042 » Fri Mar 26, 2010 2:40 pm

Hay un ejemplo en los samples?

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

Post by Rathinagiri » Fri Mar 26, 2010 5:43 pm

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.

t57042
Posts: 148
Joined: Tue Mar 16, 2010 9:46 am
Location: belgium
Has thanked: 2 times
Been thanked: 4 times

Post by t57042 » Sat Mar 27, 2010 11:18 am

Indeed, and I don't find any example where the colums are determined after vreation of the grid.

User avatar
srvet_claudio
Posts: 1958
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Has thanked: 32 times
Been thanked: 125 times
Contact:

Post by srvet_claudio » Sat Mar 27, 2010 4:09 pm

t57042 wrote:Is it possible to determine the fields to diplay at runtime in a gridcontrol?
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. 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

Un saludo cordial,
Claudio Soto
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com

t57042
Posts: 148
Joined: Tue Mar 16, 2010 9:46 am
Location: belgium
Has thanked: 2 times
Been thanked: 4 times

Post by t57042 » Sat Mar 27, 2010 6:07 pm

Muchas gracias

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

Post by Pablo César » Wed Mar 06, 2013 10:34 pm

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
Fantástico, esta alternativa me ayudó mucho. Muchas gracias Dr. Claudio !

--- 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

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 » Thu Mar 07, 2013 2:39 am

Excelente Dr. Claudio.... Muy bien....

Saludos
Polo

Post Reply