GrapeCity MultiRow Windows Forms Documentation
Editing Cells

By default, the GcMultiRow control allows users to edit cells, confirm the edit, or cancel the edit. This topic describes editing in the GcMultiRow control.

User Editing

By default, the user can start editing a cell by:

To find out how the user initiated the editing, you can get the value of the CellBeginEditEventArgs.BeginEditReason property in the CellBeginEdit event.

To complete editing a cell, the user can:

To find out how the user completed editing, return the value of the CellEndEditEventArgs.EndEditReason property in the CellEndEdit event.

To cancel the editing of the cell (to discard the edited values), the user can press the Esc key.

To find out whether the editing was canceled, return the value of the CellEndEditEventArgs.EditCanceled property inside the GcMultiRow.CellEndEdit event.

Any action assigned to a single key is implemented as a shortcut key. You can change the keys or actions mapped to the shortcut keys. To read more about customizing shortcut keys, see Shortcut Keys.

The editing feature provided through character keys or double-clicking is the default behavior when the value of the GcMultiRow.EditMode property is set to EditOnKeystrokeOrShortcutKey. To change this behavior, change the value of the GcMultiRow.EditMode property.

Using Code

You can change a cell's edit mode without using shortcut keys as in the following code.

[VB]

GcMultiRow1.Focus()
GcMultiRow1.BeginEdit(False)

[CS]

gcMultiRow1.Focus();
gcMultiRow1.BeginEdit(false);

A cell cannot change to edit mode when the grid is in the Display mode or when the cells are in read-only mode.

Use the GcMultiRow.EndEdit method to confirm the editing. Use the GcMultiRow.CancelEdit method to cancel the editing. To explicitly commit the edits to the datasource, use the GcMultiRow.CommitEdit method.

You can also change a cell to edit mode by directly calling the actions of the shortcut keys.

Using Code

This example sets the edit mode.

[VB]

GcMultiRow1.Focus()
GrapeCity.Win.MultiRow.EditingActions.BeginEdit.Execute(GcMultiRow1)

[CS]

gcMultiRow1.Focus();
GrapeCity.Win.MultiRow.EditingActions.BeginEdit.Execute(gcMultiRow1);

When you begin editing using the GcMultiRow.BeginEdit method, the value of the CellBeginEditEventArgs.BeginEditReason property of the CellBeginEdit event becomes Programmatically and you can check that the editing is being done by the developer. When the editing begins due to calling the action of a shortcut key, the value of the CellBeginEditEventArgs.BeginEditReason property becomes ShortcutKey; therefore, you can easily differentiate whether the editing is a result of coding or due to a simulation of a user action.

Continuous Input or Automatic Editing

There is a Continuous Input mode provided in the grid, which puts the cell in edit mode as soon as the cell receives the focus.

Using Code

This example sets the EditMode property to EditOnEnter.

[VB]

GcMultiRow1.EditMode = GrapeCity.Win.MultiRow.EditMode.EditOnEnter

[CS]

gcMultiRow1.EditMode = GrapeCity.Win.MultiRow.EditMode.EditOnEnter;

The result of editing in the continuous input mode can be confirmed by pressing the Enter key or by moving the focus from the cell.

Canceling Editing

You can control whether the cell enters edit mode by using the CellBeginEditEventArgs.Cancel property of the GcMultiRow.CellBeginEdit event. For example, you can specify whether to allow the editing of the cell based on the cell's value.

Restricting Editing

If it is clear while designing the template that the editing of cells should not be allowed, you can restrict the editing of cells, disable the events, or make the cells read-only. See the following topics for details:

You can change the values of these properties at runtime also.

Getting the Edit State

You can check whether the cell is in edit mode by using the GcMultiRow.IsCurrentCellInEditMode property or Cell.IsInEditMode property.

Controls in Edit Mode

The cell editing control is shown in the cells currently in edit mode. For example, the TextBoxEditingControl handles the editing in a text box cell. The cell editing control can be accessed using the GcMultiRow.EditingControl property and GcMultiRow.EditingControlShowing event.

Using Code

The following code compares the value before and during editing while validating the value.

[VB]

Imports GrapeCity.Win.MultiRow

Private Sub GcMultiRow1_CellValidating(ByVal sender As System.Object, _
    ByVal e As CellValidatingEventArgs) Handles GcMultiRow1.CellValidating
    If TypeOf GcMultiRow1.CurrentCell Is TextBoxCell Then
        Dim beforeEdit As Object = _
            GcMultiRow1.Rows(e.RowIndex).Cells(e.CellIndex).Value
        If beforeEdit IsNot Nothing Then
            Console.WriteLine("Value before editing:{0}", beforeEdit.ToString())
        Else
            Console.WriteLine("Value before editing:(None)")
        End If

        If GcMultiRow1.EditingControl IsNot Nothing Then
            Console.WriteLine("Value during editing:{0}", GcMultiRow1.EditingControl.Text)
        Else
            Console.WriteLine("Value during editing:(None)")
        End If
    Else
        Console.WriteLine("The present cell is not string type cell.")
    End If
End Sub

[CS]

using GrapeCity.Win.MultiRow;

private void gcMultiRow1_CellValidating(object sender, CellValidatingEventArgs e)
{
    if (gcMultiRow1.CurrentCell is TextBoxCell)
    {
        object beforeEdit = gcMultiRow1.Rows[e.RowIndex].Cells[e.CellIndex].Value;
        if (beforeEdit != null)
            Console.WriteLine("Value before editing:{0}", beforeEdit.ToString());
        else
            Console.WriteLine("Value before editing:(None)");

        if (gcMultiRow1.EditingControl != null)
            Console.WriteLine("Value during editing:{0}", gcMultiRow1.EditingControl.Text);
        else
            Console.WriteLine("Value during editing:(None)");
    }
    else
    {
        Console.WriteLine("The present cell is not string type cell.");
    }
}

The following code changes the forecolor and backcolor only while editing.

[VB]

Imports GrapeCity.Win.MultiRow
Private Sub GcMultiRow1_EditingControlShowing(ByVal sender As System.Object, ByVal e As EditingControlShowingEventArgs) Handles GcMultiRow1.EditingControlShowing
    e.CellStyle.BackColor = Color.Azure
    e.CellStyle.ForeColor = Color.Blue
End Sub

[CS]

using GrapeCity.Win.MultiRow;

private void gcMultiRow1_EditingControlShowing(object sender, EditingControlShowingEventArgs e)
{
    e.CellStyle.BackColor = Color.Azure;
    e.CellStyle.ForeColor = Color.Blue;
}
See Also

 

 


Copyright © GrapeCity, inc. All rights reserved.

Support Options