Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Dynamic checkbox caption in grid?
Message
De
28/05/2002 23:05:10
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Divers
Thread ID:
00655970
Message ID:
00662279
Vues:
24
>Is it possible to dynamically change the caption of a checkbox in a grid column to display "Yes" or "No" according to the datasource for the checkbox? When first asked by the client I gave the standard "Sure" but now I'm *not* so sure.
>
>Several times I've had it working except for an occasional "echo" into the adjacent row as long as focus remains in that column. Nothing I've tried displays the correct values after focus shifts to another column.

I've tried a different approach - stuffing a checkbox with a variable caption into the grid at runtime, and it's extremely flaky. First off, the checkbox becomes read-only and won't get focus. Second, it seems to work for a while, but just try clicking the same checkbox about 6-7 times (or do it with the space key, even faster), you'll see the value changing not only on the current record, but on other records as well (or just the captions changing, I wouldn't know). Third, if you're sitting on an unbuffered unlocked record, changing the value in the checkbox won't try to lock the record, you get a "record is not locked".

Here's the code, see for yourself. Just have a table with a logical field selected and call this:
* browse.prg
LPARAMETERS justaparameter
oForm=Createobject("browform")
oForm.Show(PCOUNT())
Return oForm

Define Class browform As Form
	Add Object oGrid As Grid With RecordSource=Alias()

	Procedure Activate
		This.Caption="Browse "+this.ogrid.recordsource
		This.Resize
	Endproc

	Procedure oGrid.Init
		Local i, N
		SET PROCEDURE TO browse.prg
		For i=1 To This.ColumnCount
			With This.Columns[i]
				cSource=.ControlSource
				cType=Type(cSource)
				Do Case
					Case cType="L"
						.addobject("check","gcheck")
						.Check.visible=.t.
						.RemoveObject("text1")
						.CurrentControl="check"
						.Check.ReadOnly=.F.
						.Sparse=.f.
				Endcase
			Endwith
		Endfor

	Endproc


	Procedure Resize
		With This.oGrid
			.Top=0
			.Left=0
			.Width=This.Width
			.Height=This.Height
			.SetAll("selectonentry",.F.)
		Endwith
	Endproc

Enddefine


DEFINE CLASS gcheck AS checkbox

	caption_yes = ("Yes")
	caption_no = ("No")
	Name = "gcheck"


	PROCEDURE Init
		* fire value_assign
		this.value=this.value
	ENDPROC
	
	PROCEDURE value_assign
		LPARAMETERS vNewVal
		if !empty(m.vNewVal) and !empty(this.caption_yes)
			this.caption=this.caption_yes
		endif
		if Empty(m.vNewVal) and !empty(this.caption_no)
			this.caption=this.caption_no
		endif
		this.refresh
		THIS.Value = m.vNewVal
	ENDPROC

	PROCEDURE InteractiveChange
		this.value=this.value
	ENDPROC

	PROCEDURE Click
		dodefault()
		this.refresh
		nodefault
	ENDPROC

ENDDEFINE

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform