Back to Devexpress

EditFormPage Class

mobilecontrols-devexpress-dot-xamarinforms-dot-datagrid-8160dada.md

latest8.0 KB
Original Source

EditFormPage Class

The page that allows users to edit grid’s cell values.

Namespace : DevExpress.XamarinForms.DataGrid

Assembly : DevExpress.XamarinForms.Grid.dll

NuGet Package : DevExpress.XamarinForms.Grid

Declaration

csharp
public class EditFormPage :
    ContentPage

Remarks

EditFormPage is the DataGridView‘s standard edit form that allows users to edit cell values. You can specify a gesture (for example, tap or double tap) that invokes it.

To customize the edit form appearance, use properties of the DataFormView object that the EditFormPage.Content property returns.

The default form contains editors for all columns within the grid. Editors are arranged in a column from top to bottom. Each editor displays a caption (the column’s display name or the GridColumn.EditFormCaption property value) to the left of the edit field. You can define a custom template to replace the default view of the edit form. This can be useful when you need to change a set of editors displayed in the form, specify a custom editor caption, or adjust editor sizes.

Examples

How to: Enable the Edit Form

This example shows how to set up the grid to display the Edit Values form when a user taps a cell. The grid is bound to a collection of orders.

  1. Subscribe to the DataGridView.Tap event.

  2. In the event handler:

  3. In the App.xaml.cs file, assign a NavigationPage instance to the Application.MainPage property and add the MainPage content page to the navigation stack (the application’s root page):

The grid now displays the Edit Values form when a user taps a data cell.

View Example

How to: Customize the Edit Form Appearance

This example demonstrates how to customize the grid’s edit form appearance.

Use the EditFormPage object’s Content property to access a DataFormView object that is the form’s default view and stores its appearance settings:

To specify a custom caption for an editor, use the GridColumn.EditFormCaption property.

xaml
<dxg:DataGridView x:Name="dataGridView"
                  EditorShowMode="Never"
                  ItemsSource="{Binding Path=OutlookData}"
                  Tap="Handle_Tap">
    <dxg:DataGridView.Columns>
        <dxg:NumberColumn FieldName="Id" Width="70" IsReadOnly="true"/>
        <dxg:ComboBoxColumn FieldName="Priority" MinWidth="120"/>
        <dxg:TextColumn FieldName="From.Name" Caption="From" MinWidth="150" ClearIconVisibility="Auto"/>
        <dxg:DateColumn FieldName="Sent" Width="110"/>
        <dxg:TimeColumn FieldName="Time" Width="100"/>
        <dxg:NumberColumn FieldName="Size" Width="120" DisplayFormat="{}{0} B" IsUpDownIconVisible="True" UpDownIconAlignment="Start"/>
    </dxg:DataGridView.Columns>
</dxg:DataGridView>
csharp
using Xamarin.Forms;
using DevExpress.XamarinForms.DataGrid;

namespace DataGridExample {
    public partial class MainPage : ContentPage {
        public MainPage() {
            InitializeComponent();
        }

        private void Handle_Tap(object sender, DataGridGestureEventArgs e) {
            if (e.Item != null) {
                var editForm = new EditFormPage(grid, grid.GetItem(e.RowHandle));

                DataFormView view = (DataFormView)editForm.Content;
                view.BackgroundColor = Color.FromHex("#333333");
                view.EditorLabelFontSize = 18;
                view.EditorLabelColor = Color.White;
                view.EditorPadding = new Thickness(0, 0, 0, 30);
                view.ContentPadding = new Thickness(10, 10, 10, 10);

                Navigation.PushAsync(editForm);
            }
        }
    }
}

How to: Define a Custom Template for the Edit Form

This example shows how to create a custom view for the grid’s edit form and set up the grid to invoke this form when a user double taps a cell.

The grid is bound to a collection of Employee objects and contains columns to display employee information (photo, name, position, phone, address, hire and birth dates, access level, and information about vacation). A custom edit form will display an employee’s photo and name, and contain editors to modify employee’s phone and address.

Custom Edit Form

Grid Columns

Follow the steps below to implement a custom edit form.

  1. Define a data template to be a content for the edit form page. In this example, it is a Xamarin.Forms.Grid with a set of labels and editors inside. Its BindingContext is an EditRowViewModel object. Use its Item property to access an object that represents a data source’s record (Employee) and bind editors to its properties.

  2. In the grid’s DoubleTap event handler, create an EditFormPage instance and pass the specified data template to its constructor as a third parameter.

  3. In the App.xaml.cs file, assign a NavigationPage instance to the Application.MainPage property and add the MainPage content page to the navigation stack (the application’s root page):

View Example

Inheritance

Object EditFormPage

See Also

EditFormPage Members

DevExpress.XamarinForms.DataGrid Namespace