Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Checkbox in grid dynamically change the caption
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
01686606
Message ID:
01686610
Views:
38
>>Hi,
>>
>>I have a grid build from a DBF table. One of the columns is set to the value "STATUS='A'". This resolves into .T. or .F.
>>I want to shows this in the grid as a check box. And I can dynamically replace the column from text to the check box as follows:
>>
>>.RemoveObject( "Text1" )	
>>cNewControlName = "." + ALLTRIM( GRID_DATA.OPT_CONTR1 )
>>.AddObject( ALLTRIM( GRID_DATA.OPT_CONTR1 ), ALLTRIM( GRID_DATA.OPT_CONTR2 ) )			
>>.sparse = .F.
>>
>>The value in OPT_CONTR2 is "CHECKBOX_CONTROL"
>>The value in OPT_CONTR1 is "STATUS" (or whatever word I choose).
>>The PRG has a function "CHECKBOX_CONTROL" which simply looks like this:
>>
>>DEFINE CLASS CHECKBOX_CONTROL AS CHECKBOX
>>
>>	OPT_CONTR1 = ""
>>	OPT_CONTR2 = ""
>>	OPT_CONTR3 = ""
>>	OPT_CONTR4 = ""
>>	OPT_CONTR5 = 0.00
>>	OPT_CONTR6 = ""
>>	OPT_CONTR7 = .F.
>>	OPT_CONTR8 = .F.
>>	ROW_HEIGHT = 0.00
>>						
>>ENDDEFINE
>>
>>The above shows all rows in the grid as a checkbox. However, regardless of the value (STATUS="A" or STATUS="I"), the check box has a caption equal in OPT_CONTR1. If the value in OPT_CONTR1 is "STATUS", all rows show the checkbox with the caption STATUS.
>>I would like the caption to change, depending on the value in the field STATUS. For example, when the STATUS="A", the caption should say "Active". When the value in the row is STATUS="I", the caption should say "Inactive."
>>
>>How do I do it?
>>
>>TIA
>
>
>Use some of Dynamic* method of the Grid to change the Caption of checkbox.
>
>
>Here one rough example:
>
>oForm = CREATEOBJECT([form1])
>oForm.Show(1)
>
>
>
>
>**************************************************
>*-- Form:         form1 (d:\all_zapl\additional_programs\upgrade\aaa.scx)
>*-- ParentClass:  form
>*-- BaseClass:    form
>*-- Time Stamp:   05/25/23 11:00:01 AM
>*
>DEFINE CLASS form1 AS form
>
>
>    Top = 0
>    Left = 0
>    DoCreate = .T.
>    Caption = "Form1"
>    *-- XML Metadata for customizable properties
>    _memberdata = [<VFPData><memberdata name="setcaption" display="SetCaption"/></VFPData>]
>    Name = "Form1"
>
>
>    ADD OBJECT grid1 AS grid WITH ;
>        ColumnCount = 2, ;
>        Anchor = 15, ;
>        Height = 200, ;
>        Left = 19, ;
>        Top = 28, ;
>        Width = 320, ;
>        Name = "Grid1", ;
>        Column1.Sparse = .F., ;
>        Column1.Name = "Column1", ;
>        Column2.Name = "Column2"
>
>
>    PROCEDURE setcaption
>        thisform.Grid1.ColUMN1.Check1.Caption = ALLTRIM(Test.Fld2)
>        RETURN thisform.Grid1.ColUMN1.BackColor
>    ENDPROC
>
>
>    PROCEDURE Init
>       WITH thisform.Grid1.Column1 AS Column
>            .AddObject("Check1","CheckBox")
>            .RemoveObject("Text1")
>            .Check1.Visible = .t.
>            .CurrentControl = "Check1"
>       ENDWITH 
>    
>    
>    
>    
>        thisform.Grid1.ColuMN1.DynamicBackColor = "thisform.SetCaption()"
>    ENDPROC
>
>
>    PROCEDURE Load
>        CREATE CURSOR Test (Fld1 L, Fld2 C(20))
>        FOR lnFor = 1 TO 20
>            INSERT INTO Test VALUES (lnFor%2==0,"Caption - "+TRANSFORM(lnFor))
>        NEXT 
>        GO TOP
>    ENDPROC
>
>
>ENDDEFINE
>*
>*-- EndDefine: form1
>**************************************************
>
Thank you both, Borislav and Lutz.
I will consider both approaches. But, maybe, the simple approach will be to do away with the Caption all together. It is not so difficult for the user to understand that the box checked means "Active" and the box unchecked is "Inactive."
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform