Log In
[Expand]General Information
[Collapse]WinForms Controls
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Collapse]Data Grid
   [Expand]Getting Started
   [Expand]Binding to Data
   [Expand]Grid View
   [Expand]View Technology
   [Collapse]Data Editing
    [Collapse]Edit Form
      Custom Edit Form
    [Expand]Editing via Code
    [Expand]In-place Editors
    [Expand]Input Validation
    [Expand]New Item Row
     Tutorial: Add or Remove Rows
     Tutorial: Data Input Validation
   [Expand]Filtering and Locating Rows
   [Expand]Focus and Selection Handling
   [Expand]Processing Rows
   [Expand]Formatting Cell Values
   [Expand]Master-Detail Relationships
   [Expand]Asynchronous Image Load
   [Expand]Export and Printing
   [Expand]Appearance and Conditional Formatting
   [Expand]Batch Modifications
   [Expand]Hit Information
   [Expand]Popup Menus
   [Expand]Saving and Restoring Layouts
   [Expand]Visual Elements
   [Expand]Design-Time Features
   [Expand]End-User Capabilities
    Included Components
  [Expand]Vertical Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Map Control
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]PDF Viewer
  [Expand]TreeMap Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Report Server
[Expand]eXpressApp Framework
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Custom Edit Form

In addition to the default Edit Form, in which the editor layout is created automatically based on the options provided by the GridView.OptionsEditForm and GridColumn.OptionsEditForm properties (see the Edit Form topic for more details), you can use a custom User Control as an Edit Form. The following image shows an example of a custom Edit Form.

Expanded Implementing a Custom EditForm

To implement a custom Edit Form, do the following:

  1. Create a UserControl that will be a custom Edit Form by deriving it from the EditFormUserControl class. The EditFormUserControl object provides properties and methods for binding editors to the grid control's data source.
  2. Use the Windows Forms Designer to add editors to the form that will represent data record fields and to arrange the editors in a specific manner. The following image demonstrates a sample layout.

    It is recommended that you create an editor layout within the Edit Form using the LayoutControl. The LayoutControl is a layout manager. It maintains a consistent control layout by preventing controls from being overlapped or misaligned, even when font settings are changed or the form is resized.

  3. Bind the created editors to data source fields.

    The EditFormUserControl provides a data binding mechanism that allows you to bind editors within the EditFormUserControl to an underlying data source. The EditFormUserControl provides the BoundFieldName and BoundPropertyName extender properties to other controls because it supports the ProvidePropertyAttribute.

    The BoundFieldName property specifies the field name in the underlying data source to which an editor is bound. You can assign the field name to this property at design time, or via the EditFormUserControl.SetBoundFieldName method in code.

    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 the BoundFieldName property value has been assigned, the BoundPropertyName property is automatically set to one of the following values.

    • EditValue - if the editor is a BaseEdit descendant.
    • Text - for all other types of controls.

    You can change the default value of the BoundPropertyName extender property at design time or via the EditFormUserControl.SetBoundPropertyName method in code.

    In the following image, the BoundFieldName extender property of the TextEdit named "textEdit3" is set to Price. The BoundPropertyName property is automatically set to EditValue, since the TextEdit is of the BaseEdit type and contains an edit value in the BaseEdit.EditValue property.

    You can also specify the BoundFieldName and BoundPropertyName extender properties in code. The EditFormUserControl provides the EditFormUserControl.SetBoundFieldName and EditFormUserControl.SetBoundPropertyName methods as part of the ProvidePropertyAttribute implementation:

    To get the BoundFieldName and BoundPropertyName property values in code, use the EditFormUserControl.GetBoundFieldName and EditFormUserControl.GetBoundPropertyName methods, respectively.

  4. To use the generated custom User Control as an Edit Form within the grid, assign an instance of this User Control to the GridOptionsEditForm.CustomEditFormLayout property:

Expanded Using a Custom Edit Form in Detail Views

By default, a custom Edit Form is not supported for detail Views. As a result, the following code, where gridView2 is a detail pattern View, will not work:

A workaround for this issue is to use separate instances of a custom Edit Form in each detail Clone View. Subscribe to the GridControl.ViewRegistered event and set the GridOptionsEditForm.CustomEditFormLayout property of the currently processed detail Clone View to a new instance of a custom Edit Form. The sample code is shown below:

Expanded See Also

How would you rate this topic?​​​​​​​