define columncontrols runtime

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
mlnr
Posts: 74
Joined: Fri Aug 28, 2015 1:52 pm
DBs Used: DBF
Location: Hungary
Has thanked: 25 times
Been thanked: 9 times

define columncontrols runtime

Post by mlnr » Tue Jan 16, 2018 12:42 pm

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: 3039
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 170 times
Been thanked: 92 times
Contact:

Post by mol » Tue Jan 16, 2018 12:55 pm

It's impossible in my opinion.
You can use virtual grid in which you can mix everything.

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

Post by Rathinagiri » Tue Jan 16, 2018 2:03 pm

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: 341
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 95 times
Been thanked: 249 times

Post by edk » Tue Jan 16, 2018 2:12 pm

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

mlnr
Posts: 74
Joined: Fri Aug 28, 2015 1:52 pm
DBs Used: DBF
Location: Hungary
Has thanked: 25 times
Been thanked: 9 times

Post by mlnr » Tue Jan 16, 2018 2:32 pm

Thank you guys for your answers.

Edward, your code is perfect for me. :)

Thanks again
Best regards,
Gabor

User avatar
mol
Posts: 3039
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 170 times
Been thanked: 92 times
Contact:

Post by mol » Tue Jan 16, 2018 2:48 pm

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

What does letter E in {'TEXTBOX','NUMERIC','999999.999','E'}

edk
Posts: 341
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 95 times
Been thanked: 249 times

Post by edk » Tue Jan 16, 2018 2:58 pm

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