PRB: Disabled Grid Controls Can Be Selected with MouseLast reviewed: October 15, 1995Article ID: Q137963 |
The information in this article applies to:
SYMPTOMSYou are able to use the mouse to select a disabled grid control. The control appears to have the focus, but no editing can be performed. This can occur when:
CAUSEThis is normal behavior for the Grid object. This situation occurs because the Grid object must change the record pointer before it can query columns or column controls for enabled = true. Once the record pointer is changed, the grid can't go back because the grid does not save a previous record pointer. It might be argued that the grid should leave the focus on the prior column before the user switches to the disabled column or control, but this leads to problems when handling two special cases:
RESOLUTIONInclude code in the AfterRowColChange event to handle cases in which the column is being changed to a disabled column or control. Following are two examples of code to accomplish this.
Example OneThe following example demonstrates the simplest case. For this example, assume that column one is always disabled, column two is never disabled, and horizontal scrolling is disabled.
LPARAMETERS nColIndex * LPARAMETERS statement required and inserted by Visual FoxPro * Check to see if you're on column one IF nColIndex = 1 * Change the active cell WITH This .ActivateCell(.RelativeRow, 2) ENDWITH ENDIFNOTE: This example makes use of the RelativeRow property. Do not use the ActiveRow property; it will not work properly. Note that the ActiveCell method assigns the focus to column two even if column two is disabled or the current control in column two is disabled.
Example TwoThe following example is slightly more robust. It can be used on scrollable grids, where the columns or controls may have a variable enabled setting. The code first checks to make sure that the current column is valid. If it is not, it starts moving through the available columns until it finds a valid column for input focus, and then sets the focus. The code wraps from the last column to the first, taking into account that several controls may exist within the column. The code leaves the focus on the current column if no columns are enabled.
LPARAMETERS nColIndex * LPARAMETERS statement required and inserted by Visual FoxPro LOCAL iLoop, iMax, lFocusSet WITH This && Grid * Initialize Loop Variables iMax = .ColumnCount iLoop = nColIndex + 1 * Check if current column is valid WITH .Columns(nColIndex) * Column is valid only if the Column's Enabled Property is True * and the CurrentControl's Enabled Property is True * Note: The EVAL function (cf. EVALUATE() online help) is used as * as an alternative to macro substitution for accessing the * column's current control lFocusSet=.Enabled .AND. EVAL("." + .CurrentControl + ".Enabled") ENDWITH * Start at next column (to the right) and cycle through all columns * until a valid column is reached or loop returns to current column * Note: If the current column is valid, lFocusSet = true and this * loop is skipped DO WHILE iLoop # nColIndex .AND. .NOT. lFocusSet * Wrap to first column if necessary IF iLoop > iMax iLoop = 1 ELSE WITH .Columns(iLoop) * If this column is Valid (same criteria as above) IF .Enabled .AND. EVAL("." + .CurrentControl + ".Enabled" ) * Set focus to column and end loop .SetFocus lFocusSet = .T. ENDIF ENDWITH * Advance to next column iLoop = iLoop + 1 ENDIF ENDDO ENDWITHNOTE: This example does not take into account columns or controls within columns that have a When event that returns False.
STATUSThis behavior is by design.
|
Additional reference words: 3.00 VFoxWin
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |