Back to Devexpress

EditFormUserControl Class

windowsforms-devexpress-dot-xtragrid-dot-views-dot-grid-57c905eb.md

latest6.0 KB
Original Source

EditFormUserControl Class

A custom edit form for the Data Grid control.

Namespace : DevExpress.XtraGrid.Views.Grid

Assembly : DevExpress.XtraGrid.v25.2.dll

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

Declaration

csharp
[DXLicenseWinForms]
public class EditFormUserControl :
    XtraUserControl,
    IExtenderProvider,
    IEditorFormTagProvider
vb
<DXLicenseWinForms>
Public Class EditFormUserControl
    Inherits XtraUserControl
    Implements IExtenderProvider,
               IEditorFormTagProvider

Remarks

The EditFormUserControl binds its editors to data fields in the grid. For this purpose, the EditFormUserControl provides the following extender properties for the contained editors:

  • the BoundFieldName property specifies the field name in the underlying data source to which the editor is bound;
  • the BoundPropertyName property specifies the editor’s property to which a field value is assigned on initializing the Edit Form, and from which a value is fetched and posted back to the grid on saving data.

If an editor is contained on a EditFormUserControl descendant, you can specify the extender properties in Designer using the Properties window as shown below.

In code, you can get and set the extender properties using the following methods:

The code snippet below shows a sample Edit Form.

csharp
using DevExpress.XtraGrid.Views.Grid;

class MyEditForm : EditFormUserControl {
    private DevExpress.XtraEditors.TextEdit textEdit1;
    public MyEditForm() {
        this.textEdit1 = new DevExpress.XtraEditors.TextEdit();
        this.textEdit1.Location = new System.Drawing.Point(0, 0);
        this.textEdit1.Size = new System.Drawing.Size(100, 22);

        this.SetBoundFieldName(this.textEdit1, "Price");
        this.SetBoundPropertyName(this.textEdit1, "EditValue");
        this.Controls.Add(this.textEdit1);
        this.Size = new System.Drawing.Size(400, 200);
    }
}
//...
gridView1.OptionsBehavior.EditingMode = GridEditingMode.EditForm;
gridView1.OptionsEditForm.CustomEditFormLayout = new MyEditForm();
vb
Public Class MyEditForm
    Inherits DevExpress.XtraGrid.Views.Grid.EditFormUserControl
    Friend WithEvents TextEdit1 As DevExpress.XtraEditors.TextEdit

    Public Sub New()
        Me.TextEdit1 = New DevExpress.XtraEditors.TextEdit()
        Me.TextEdit1.Location = New System.Drawing.Point(0, 0)
        Me.TextEdit1.Size = New System.Drawing.Size(100, 22)
        Me.TextEdit1.TabIndex = 0

        Me.SetBoundFieldName(Me.TextEdit1, "City")
        Me.SetBoundPropertyName(Me.TextEdit1, "EditValue")
        Me.Controls.Add(Me.TextEdit1)
        Me.Size = New Size(400, 200)
    End Sub
End Class

' ...
Me.GridView1.OptionsBehavior.EditingMode = DevExpress.XtraGrid.Views.Grid.GridEditingMode.EditForm
Me.GridView1.OptionsEditForm.CustomEditFormLayout = New MyEditForm()

The created custom Edit Form should be assigned to the GridOptionsEditForm.CustomEditFormLayout property.

See the Modify and Validate Cell Values topic to learn more about how to edit and validate data in the grid.

Implements

IXtraResizableControl

Inheritance

Object MarshalByRefObject Component Control ScrollableControl ContainerControl UserControl XtraUserControl EditFormUserControl

See Also

EditFormUserControl Members

Edit Data. Create Cell Editors. Validate User Input

CustomEditFormLayout

DevExpress.XtraGrid.Views.Grid Namespace