True DBGrid for WinForms | ComponentOne
End User Interaction / Navigation and Scrolling
In This Topic
    Navigation and Scrolling
    In This Topic

    The following sections describe the grid's default navigation and scrolling behavior. You always have complete control over the behavior of the TAB and arrow keys as well as the position of the current cell when a row or split boundary is reached.

    Mouse Interaction

    When the user clicks a non-current cell, the grid fires the BeforeRowColChange event. Unless this event is cancelled, the clicked cell becomes current and the grid subsequently fires the RowColChange event after any pending update operations have completed. The only exceptions to this are:

    The user can also use the mouse to manipulate the grid's scroll bars, bringing cells that lie outside the grid's display area into view. The vertical scroll bar governs rows; the horizontal scroll bar governs columns. The HScrollBar property controls whether the horizontal scroll bars are displayed, while the VscrollBar property controls the vertical scroll bar.

    Note that the scroll bars do not change the current cell. Therefore, the current cell may not always be visible.

    To respond to vertical scrolling operations in code, use the FirstRowChange event. To respond to horizontal scrolling operations in code, use the LeftColChange event.

    Clicking the Rightmost Column

    The grid always displays the leftmost column (the first visible column) in its entirety. The rightmost column, however, is usually clipped. The behavior of the last partially visible column when clicked by the user is controlled by the grid's ExposeCellMode property.

    The default value for the ExposeCellMode property is ExposeCellModeEnum.ScrollOnSelect. If the user clicks the rightmost column when it is partially visible, the grid will scroll to the left to display this column in its entirety. This may be less desirable for users who commonly click on the grid to begin editing, as the grid will always shift to the left when the user clicks on a partially visible rightmost column.

    If ExposeCellMode is set to ExposeCellModeEnum.ScrollOnEdit, the grid will not scroll when the rightmost visible column is clicked. However, if the user attempts to edit the cell, then the grid will scroll to the left to display the column in its entirety. This is how Microsoft Excel works and is probably the most familiar setting to users.

    If ExposeCellMode is set to ExposeCellModeEnum.ScrollNever, the grid will not scroll to make the rightmost column visible, even if the user subsequently attempts to edit the cell. Note that editing may be difficult if only a small portion of the column is visible. The chief reason to use this setting is to ensure enough space is available for editing (or if editing is disallowed) and to prevent the grid from shifting accidentally.

    Note that the ExposeCellMode property controls the behavior of the rightmost visible column only when the user clicks it with the mouse. If the rightmost column becomes visible by code (setting the grid's Col property) or by keyboard navigation, then the grid will always scroll to make it totally visible.

    Keyboard Interaction

    True DBGrid for WinForms includes several keyboard shortcuts that can improve users' run-time interaction experience.

    In Grid View

    By default, the user can navigate the grid with the arrow keys, the ENTER key, the TAB key, the Page Up and Page DOwn keys, and the HOME and END keys.

    Key Action
    Up/Down Arrows These keys move the current cell to adjacent rows.
    Left/Right Arrows If the AllowArrows property is True (the default), these keys move the current cell to adjacent columns. If the AllowArrows property is False, then these keys move focus from control to control and cannot be used to move between cells.
    ENTER By default, the ENTERkey behaves in the same manner as the RIGHT ARROW key, by moving the current cell from left to right along the adjacent columns. The behavior for the ENTER key can be modified by using the DirectionAfterEnter property. When editing a cell, the ENTER key will save edits and then movie to the next cell.
    TAB If the TabAction property is set to Control Navigation (the default), the TAB key moves focus to the next control on the form as determined by the tab order. If the TabAction property is set to ColumnNavigation or GridNavigation, the TAB key moves the current cell to the next column, while SHIFT+TAB moves to the previous column. The differences between column and grid navigation are discussed in the next section.
    PAGE UP, PAGE DOWN These keys scroll the grid up or down an entire page at a time. Unlike the vertical scroll bar, thePAgE Up and PAgE DOWn keys change the current row by the number of visible rows in the grid's display. When paging up, the current row becomes the first row in the display area. When paging down, the current row becomes the last row in the display area, including the AddNew row. The current column does not change.
    HOME, END These keys move the current cell to the first or last column. If necessary, the grid will scroll horizontally so that the current cell becomes visible. The current row does not change. If the current cell is being edited, HOME and END move the insertion point to the beginning or end of the cell's text.
    F2 Switch between Edit mode (with insertion point displayed) and Navigation mode in a datasheet. When working in a form or report, press ESC to leave Navigation mode.
    F4 This key shows or hides a combo box.
    ALT+DOWN ARROW You can use this key combination to show a combo box, such as a C1TrueDBG
    ALT + LEFT ARROW Collapses all open child grids.
    ALT+RIGHT ARROW Expands a child grid.
    DELETE The DELETE button deletes the row. In edit mode, the DELETE key deletes the selected contents of a cell, deleting content to the right of the cursor.
    SPACE BAR The SPACE BAR key initiates button clicks and check box and radio button selection and de-selection.
    CTRL+C This key combination copies the selected content to the Clipboard
    CTRL+V This key combination pastes the contents of the Clipboard to the selected location.
    CTRL+X This key combination cuts the selected content and copies it to the Clipboard
    BACKSPACE, CTRL+H In Edit mode you can use the BACKSPACE key or the CTRL+H key combination to delete content from a cell, deleting content to the left of the cursor.
    TAB The TAB key ends cell editing mode, saving any content changes and leaving the current cell selected.
    INSERT In cell editing mode, the INSERT key changes the way text is entered in a cell. When the INSERT key is active, inputted text overwrites existing content.
    CTRL+UP/DOWN ARROW These key combinations allow you to navigate in a list box. The CTRL+UP ARROW key combination allows you to navigate up to the previous item in a list box. The CTRL+DOWN ARROW lets you navigate down to the next item.

    Navigation at Row Boundaries

    At row boundaries, namely the first and last column, grid navigation depends on the WrapCellPointer property. The following explanation assumes that the AllowArrows property is True, and that the TabAction property is set to either ColumnNavigation or GridNavigation.

    Key Action
    Left/Right Arrows If the WrapCellPointer property is set to True, the current cell wraps across row boundaries. If the current cell is in the last column, the RIGHT ARROW key moves it to the first column of the next row. If the current cell is in the first column, the LEFT ARROW key moves it to the last column of the previous row. If the WrapCellPointer property is set to False (default), these keys cannot move the current cell at row boundaries.
    TAB If the TabAction property is ColumnNavigation, the cell pointer does not wrap to an adjacent row, and the WrapCellPointer property is ignored. If the current cell is in the last column, TAB moves focus to the next control in the tab order. If the current cell is in the first column, SHIFT+TAB moves focus to the previous control in the tab order. If the TabAction property is GridNavigation and WrapCellPointer is True, TAB and SHIFT+TAB move the current cell to the next or previous row. The current cell will not cross row boundaries if WrapCellPointer is False.

    Navigation at Split Boundaries

    At split boundaries, grid navigation depends on the TabAcrossSplits property as follows:

    Key Action
    Left/Right Arrows If the TabAcrossSplits property is set to True, these keys move the current cell across split boundaries to the next or previous split. If the TabAcrossSplits property is set to False (default), the behavior of these keys at split boundaries will be the same as their behavior at row boundaries. Note that a split's AllowFocus property must be True in order for these keys to move the current cell to that split.
    TAB The TAB and SHIFT+TAB keys honor TabAcrossSplits as previously described for the arrow keys.

    Restricting Cell Navigation

    The BeforeRowColChange event can be used to prevent the user from moving to a different cell, regardless of whether the current cell is modified. Set the Cancel argument to True to keep another cell from becoming current.

    If the current cell has been modified, use the BeforeColUpdate event to examine its value before moving to another grid cell. If the value entered is invalid, set the Cancel argument to True to prevent the current cell from changing, and optionally beep or display an error message for the user. The BeforeColUpdate event provides a flexible way to validate user input and restrict cell navigation.

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Private Sub C1TrueDBGrid1_BeforeColUpdate(ByVal sender As Object, ByVal e As C1.Win.C1TrueDBGrid.BeforeColUpdateEventArgs) Handles C1TrueDBGrid1.BeforeColUpdate
        Dim CharCode As Integer
        If e.ColIndex = 1 Then
     
            ' Data in Column 1 must start with upper case.
            CharCode = Asc(Me.C1TrueDBGrid1.Columns(1).Text)
            If CharCode > 64 And CharCode < 91 Then Exit Sub
            
            ' Display warning message for user.
            MessageBox.Show("Last name must start with upper case")
        
            ' Data validation fails, prohibit user from moving to another cell.
            e.Cancel = True
        End If
    End Sub
    

    To write code in C#

    C#
    Copy Code
    private void c1TrueDBGrid1_BeforeColUpdate(object sender, C1.Win.C1TrueDBGrid.BeforeColUpdateEventArgs e) {
        int CharCode;
        if ( e.ColIndex == 1 ) 
        {
            // Data in Column 1 must start with upper case.
            CharCode = this.c1TrueDBGrid1.Columns[1].Text[0];
            if ( CharCode > 64 && CharCode < 91 ) return;
     
            // Display warning message for user.
            MessageBox.Show("Last name must start with upper case");
     
            // Data validation fails, prohibit user from moving to another cell.
            e.Cancel = true;
        }
    }