define columncontrols runtime

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
mlnr
Posts: 126
Joined: Fri Aug 28, 2015 1:52 pm
DBs Used: DBF

define columncontrols runtime

Post by mlnr »

Hi,

I would like to solve the following.

There are products in a grid. (name, quantity)
These products have a certain feature that specifies, that only integers or even fractions can be given as an amount.

e.g.
item1 3.6 (kg)
item2 5 (pieces-only integer)
item3 7 (pieces-only integer)
item4 0.2 (kg)
...
etc.

Code: Select all

//if kg
COLUMNCONTROLS { { 'TEXTBOX', 'CHARACTER'}, { 'TEXTBOX','NUMERIC','99999.99','E'}}                   
//if pcs
COLUMNCONTROLS { { 'TEXTBOX', 'CHARACTER'}, { 'TEXTBOX','NUMERIC','99999'}}                   
How can i define this line by line?

Thank you in advance.
Best regards,
Gabor
User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: define columncontrols runtime

Post by mol »

It's impossible in my opinion.
You can use virtual grid in which you can mix everything.
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: define columncontrols runtime

Post by Rathinagiri »

Yes, it is possible I think.

It is done somewhere else in the forum. I will also search.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: define columncontrols runtime

Post by edk »

I can do it, for example, in this way:

Code: Select all

#include "hmg.ch"
Function Main()

select 1
Use ptvartic Alias Articulos

aCtrl_1 := {'TEXTBOX','CHARACTER'}
aCtrl_2 := {'TEXTBOX','CHARACTER'}
aCtrl_3 := {'TEXTBOX','CHARACTER'}
aCtrl_4 := {'TEXTBOX','NUMERIC','9999999999'}

DEFINE WINDOW Form_1 ;
	AT 0,0 ;
	WIDTH 522 HEIGHT 540 ;
	TITLE "Products in the Stock" ;
	FONT "Segoe UI" SIZE 09 ;
	MAIN NOSIZE ;
	ON RELEASE DbCloseAll()
					
	@ 10, 10 GRID Grid_1	;
		WIDTH 495	;
		HEIGHT 490 	;	
		HEADERS { "Code", "Description", "Unit", "In Stock" } ;
		WIDTHS { 55, 290, 50, 90 }	;
		EDIT ;
		VALUE {9,2} ;
		COLUMNCONTROLS { aCtrl_1 , aCtrl_2 , aCtrl_3 , aCtrl_4 } ;
		FONT "Segoe UI" SIZE 09 ;
		BACKCOLOR { 244,244,244 } ;
		ROWSOURCE "Articulos" ;
		COLUMNFIELDS { "Articulos->f_cve_art", "Articulos->f_nomb_art", "Articulos->UNIT", "Articulos->Q" } ;
		COLUMNWHEN { { || .T. } ,  { || .T. } , { || .T. } ,  { || chkkg() }  } ;
		NOLINES ;
		JUSTIFY { BROWSE_JTFY_LEFT, BROWSE_JTFY_LEFT, BROWSE_JTFY_LEFT, BROWSE_JTFY_RIGHT }
		
END WINDOW
Form_1.Grid_1.SETFOCUS
CENTER WINDOW Form_1
ACTIVATE WINDOW Form_1
Return Nil


FUNCTION chkkg()
Local idx:=_HMG_SYSDATA [ 203 ]
Local aCtrl_1 := {'TEXTBOX','CHARACTER'}
Local aCtrl_2 := {'TEXTBOX','CHARACTER'}
Local aCtrl_3 := {'TEXTBOX','CHARACTER'}
Local aCtrl_4, aControls

IF Form_1.Grid_1.CellEx( Form_1.Grid_1.CellRowFocused , 3 )#'kg'
	aCtrl_4 := {'TEXTBOX','NUMERIC','9999999999'}
ELSE
	aCtrl_4 := {'TEXTBOX','NUMERIC','999999.999','E'}
ENDIF
aControls:={ aCtrl_1 , aCtrl_2 , aCtrl_3 , aCtrl_4 } 
_HMG_SYSDATA [ 40 ] [idx] [ 2 ] := aControls
RETURN .T.

Attachments
GRID_13.7z
(1.62 KiB) Downloaded 183 times
mlnr
Posts: 126
Joined: Fri Aug 28, 2015 1:52 pm
DBs Used: DBF

Re: define columncontrols runtime

Post by mlnr »

Thank you guys for your answers.

Edward, your code is perfect for me. :)

Thanks again
Best regards,
Gabor
User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: define columncontrols runtime

Post by mol »

Wow!
Nice sample!
I don't like to modify _HMG_SYSDATA.

What does letter E in {'TEXTBOX','NUMERIC','999999.999','E'}
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: define columncontrols runtime

Post by edk »

mol wrote: Tue Jan 16, 2018 2:48 pm What does letter E in {'TEXTBOX','NUMERIC','999999.999','E'}
TextBox control
Format String (Allowed in Numeric Textbox Only):
C : Displays CR after positive numbers
X : Displays DB after negative numbers
( : Encloses negative numbers in parentheses
E : Displays numbers in British format

http://www.hmgforum.com/hmgdoc/data/format.htm
Post Reply