Back to Devexpress

GridView.EditFormPrepared Event

windowsforms-devexpress-dot-xtragrid-dot-views-dot-grid-dot-gridview-c41b9586.md

latest6.4 KB
Original Source

GridView.EditFormPrepared Event

Allows you to customize the Edit Form that is about to be displayed.

Namespace : DevExpress.XtraGrid.Views.Grid

Assembly : DevExpress.XtraGrid.v25.2.dll

NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation

Declaration

csharp
[DXCategory("Editor")]
public event EditFormPreparedEventHandler EditFormPrepared
vb
<DXCategory("Editor")>
Public Event EditFormPrepared As EditFormPreparedEventHandler

Event Data

The EditFormPrepared event's data class is EditFormPreparedEventArgs. The following properties provide information specific to this event:

PropertyDescription
BindableControlsProvides access to the collection of controls used to edit the processed data record. Controls are indexed by field names or grid columns. Inherited from EditFormEventArgsBase.
PanelGets the container that arranges editors and buttons on the Edit Form. Inherited from EditFormEventArgsBase.
RowHandleGets the handle that identifies the grid row for which the Edit From is displayed/hidden. Inherited from EditFormEventArgsBase.

The event data class exposes the following methods:

MethodDescription
FocusField(GridColumn)Sets input focus to the editor that corresponds to the specified GridColumn.
FocusField(String)Sets input focus to the editor that corresponds to the grid column with the specified GridColumn.FieldName.

Remarks

Before the EditFormPrepared event, the GridView.EditFormShowing event fires, allowing you to cancel the action.

Example

When the Edit Form is displayed, focus moves to the first editor within the Edit Form. The following example shows how to handle the GridView.EditFormPrepared event to set focus to an editor corresponding to the focused GridColumn.

csharp
public partial class Form1 : Form {
    public Form1() {
        InitializeComponent();
        gridView1.EditFormPrepared += gridView1_EditFormPrepared;
    }

    private void gridView1_EditFormPrepared(object sender, DevExpress.XtraGrid.Views.Grid.EditFormPreparedEventArgs e) {
        GridView view = sender as GridView;
        if (e.BindableControls[view.FocusedColumn] != null)
            e.FocusField(view.FocusedColumn);
    }
}
vb
Public Partial Class Form1
    Inherits Form
    Public Sub New()
        InitializeComponent()
        AddHandler gridView1.EditFormPrepared, AddressOf gridView1_EditFormPrepared
    End Sub

    Private Sub gridView1_EditFormPrepared(sender As Object, e As DevExpress.XtraGrid.Views.Grid.EditFormPreparedEventArgs)
        Dim view as GridView = sender
        If e.BindableControls(view.FocusedColumn) IsNot Nothing Then
            e.FocusField(view.FocusedColumn)
        End If
    End Sub
End Class

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the EditFormPrepared event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-grid-filter-lookup-column-based-on-another-column-editform/CS/FilterLookUpsEditForm/FormSingleSource.cs#L33

csharp
gridView1.OptionsBehavior.EditingMode = GridEditingMode.EditFormInplace;
    gridView1.EditFormPrepared += new EditFormPreparedEventHandler(gridView1_EditFormPrepared);
}

winforms-grid-filter-lookup-column-based-on-another-column-editform/VB/FilterLookUpsEditForm/FormSingleSource.vb#L32

vb
gridView1.OptionsBehavior.EditingMode = GridEditingMode.EditFormInplace
    AddHandler gridView1.EditFormPrepared, AddressOf gridView1_EditFormPrepared
End Sub

See Also

FocusField

EditFormShowing

EditFormHidden

Rows

GridView Class

GridView Members

DevExpress.XtraGrid.Views.Grid Namespace