CurrentControl, DynamicCurrentControl, Sparse

These properties (together with the actual objects in the column) determine what control you see in any particular grid cell. If a column has more than one control specified, CurrentControl indicates which should appear, unless DynamicCurrentControl has a value. In that case, the expression specified for DynamicCurrentControl determines which control shows up. Sparse specifies whether the current control (whichever property determines it) appears all the time in every row for that column or only when that cell has focus.

Usage

grcColumn.CurrentControl = cControl
cControl = grcColumn.CurrentControl
grcColumn.DynamicCurrentControl = cExpr
cExpr = grcColumn.DynamicCurrentControl
A grid column can contain as many controls as you like to allow different modes of displaying or entering the same information. These two properties determine which of the multitudes the user actually sees. Like the other Dynamic... properties, DynamicCurrentControl expects a character string containing an expression. The expression itself should evaluate to the name of a control as a character string. (This is yet another place where we're glad FoxPro offers multiple sets of string delimiters.)If DynamicCurrentControl evaluates to a control the column actually contains, that value supersedes any value in CurrentControl. Although DynamicCurrentControl is pretty dynamic, fortunately it's not so dynamic that the control actually changes while you're sitting on it, even if the expression's value changes.You can't use "This" in the expression to refer to the grid column. That's because the expression gets evaluated not in a method of the column, but at the grid or form level. You need to use ThisForm.TheGrid'sName.TheColumn, instead.

Example

* Say a particular column has a ControlSource of nFld. You can
* put a text box and a spinner in the column and show the user
* the text box for odd values and the spinner for even values.
* Why? Why not? 
ThisForm.grdMyGrid.grcNFld.DynamicCurrentControl= ;
   "IIF(MOD(nfld,2)=0,'spnNFld','txtNFld')"
 
* If, on the other hand, we'd just like to have the user see the
* spinner every time:
ThisForm.grdMyGrid.grcNFld.CurrentControl = "spnNFld"

Usage

grcColumn.Sparse = lHideControl
lHideControl = grcColumn.Sparse
One of the coolest features of Visual FoxPro is putting any control you want in a grid. However, looking at a grid full of combo boxes and spinners and check boxes could drive someone nuts. That's where Sparse comes in. When you set Sparse to .T. (the default), the current control for a column shows only when a cell of that column has focus and shows only for the cell with focus. In many cases, it's a lot nicer to look at only the value as text until you're ready to edit it. Then, you want to see the combo or check box or whatever.

When CurrentControl for a cell is a check box bound to a logical field and Sparse is .T., nothing at all shows when the cell doesn't have focus. It's empty. Since check boxes aren't too ugly, your best bet is probably to set Sparse .F. for those columns.


The control that shows when Sparse is .T. and a cell doesn't have focus is a text box. But you don't have any control over it at all. It's not the default text box that gets put in the column when you create the grid. It's a different text box, internal to FoxPro.Why do you care? Because, even if the control you're using for a column is a text box, when Sparse is .T., things you specify for that text box apply only to the current cell. By "things," we mean properties like InputMask and Format that you might want to see all the time. Fortunately, in VFP 5 and later, columns have Format and InputMask properties that apply when Sparse is .T. and the cell doesn't have focus. Columns also have their own BackColor and ForeColor that apply in the same circumstances. These colors also propagate down to the contained controls, unless those controls have their own.If you need more control than that (or you're in VFP 3), forget about Sparse. Instead, put both the control you want and a text box in the column. Format the text box the way you want it and set DynamicCurrentControl to an expression that chooses the text box when the cell doesn't have focus and the other control when it does. You need to compare ActiveColumn for the grid to the particular column's ColumnOrder and check ActiveRow against the record number (if you're working with records in natural order). Our example below shows how to do this.

Example

* In the same grid as above, here's the DynamicCurrentControl
* expression to use the spinner when the cell has focus and the
* text box the rest of the time:
IIF(ThisForm.grdMyGrid.ActiveColumn = ;
    ThisForm.grdMyGrid.grcNFld.ColumnOrder AND ;
    ThisForm.grdMyGrid.ActiveRow = RECNO(),"spnNFld","txtNFld")
* And, of course, we'll need:
ThisForm.grdMyGrid.grcNFld.Sparse = .F.

See Also

Column, DynamicAlignment, DynamicBackColor, DynamicFontBold, DynamicFontItalic, DynamicFontName, DynamicFontOutline, DynamicFontShadow, DynamicFontSize, DynamicFontStrikeThru, DynamicFontUnderline, DynamicForeColor, DynamicInputMask, Grid


Back to Table of Contents

Copyright © 2002-2018 by Tamar E. Granor, Ted Roche, Doug Hennig, and Della Martin. Click for license .