Hackers Guide to Visual FoxPro 7.0
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 |
| 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 |
| | 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 |
View Updates
Copyright © 2002 by Tamar E. Granor, Ted Roche, Doug Hennig, and Della Martin. All Rights Reserved.
Категории