Back to Devexpress

DataGridView.ShowingEditor Event

mobilecontrols-devexpress-dot-xamarinforms-dot-datagrid-dot-datagridview-2d11293b.md

latest3.3 KB
Original Source

DataGridView.ShowingEditor Event

Fires when a cell editor is about to be displayed and allows you to cancel the action.

Namespace : DevExpress.XamarinForms.DataGrid

Assembly : DevExpress.XamarinForms.Grid.dll

NuGet Package : DevExpress.XamarinForms.Grid

Declaration

csharp
public event ShowingEditorEventHandler ShowingEditor

Event Data

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

PropertyDescription
CancelGets or sets a value indicating whether the event should be canceled. Inherited from CancelEventArgs.
FieldNameGets the name of the data field for which an editor is about be displayed.
ItemGets an object that specifies a record in the grid’s underlying data source.
RowHandleGets the processed row’s handle.

Example

The code below shows how to prevent the Priority column from being edited if an item was sent more than a month ago.

xaml
<dxg:DataGridView x:Name="dataGridView"
                  Grid.Row="1"
                  EditorShowMode="Tap"
                  ShowingEditor="dataGridView_ShowingEditor"
                  ItemsSource="{Binding Path=OutlookData}"
                  Tap="Handle_Tap"
                  ValidateCell="DataGridView_ValidateCell"
                  ValidationError="DataGridView_ValidationError">
    <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:DataGridView.Columns>
</dxg:DataGridView>
csharp
using DevExpress.XamarinForms.DataGrid;

private void dataGridView_ShowingEditor(object sender, ShowingEditorEventArgs e) {
    DataGridView dataGridView = sender as DataGridView;
    DateTime sent = (DateTime)dataGridView.GetCellValue(e.RowHandle, "Sent");
    if (e.FieldName == "Priority" && sent < DateTime.Now.AddDays(-30))
        e.Cancel = true;
}

See Also

DataGridView Class

DataGridView Members

DevExpress.XamarinForms.DataGrid Namespace