# Keyboard management

# Default navigation

By default, the end-user edits and navigates using particular keys:

  1. Selects a Property.
  2. Presses ENTER to focus the inplace control.
  3. Types a value.
  4. Presses ENTER or ESC to terminate the editing.
  5. Presses an arrow key (or HOME, PG DOWN, …) to go to the next property.

Note

In MSPG, Enter does not set the focus to a Property value. If you prefer this behavior (for example, if you need Enter to activate a default button on a form), you can set PropertyGrid.AcceptsReturn to false.

# TAB key Navigation

Unlike MSPG, SPG supports navigation using the TAB key.

To enable TAB key navigation:

NavigationKeyMode = NavigationKeyModes.TabKey;

Additional submodes (available with the TabKeyNavigationModes enumeration) enable various options when TabKey is used:

Submode Description
TabKeyWithAutoFocus Tabbing into a property gives the focus to its inplace control and selects any text in the Textbox.
TabKeyLeavesAtExtremes Enable Shift+TAB and TAB out of the top and bottom of the PropertyGrid, transferring the focus to a next control in the parent container.
TabKeyInSubControls TAB through child controls inside the inplace control, before moving onto the next Property. The default is to TAB from one Property to the next.
TabKeyInChildProperties Expand collapsed hierarchies as required to TAB through hidden child Properties.
TabKeySkipReadonlyProperties Skip read-only Properties.
Otherwise, read-only property can take the focus, enabling Clipboard Copy.
NoSubMode (default) None of the above.

You can set this submode with the PropertyGrid.TabKeyNavigationMode property.

To restore default arrow key navigation:

NavigationKeyMode = NavigationKeyModes.ArrowKeys;

# Overriding keys

It is possible to override a key's default behavior by capturing the key before processing in ProcessKeyPreview.

# > Example

This intercepts the Delete key. Instead of giving the focus to a textbox and deleting its content, it deletes the whole Property:

protected override bool ProcessKeyPreview(ref Message m)
{
    if (m.Msg == 0x0100)
    {
        if ((Keys)m.WParam == Keys.Delete)
        {
            DeleteProperty(SelectedPropertyEnumerator);
            return true;
        }
    }

    return base.ProcessKeyPreview(ref m);
}
Last Updated: 5/25/2022, 1:18:09 PM