Data Editing
Default In-place Eremex Editors
The DataGrid control's default behavior is to use Eremex in-place editors to display and edit cell values of common data types.
The following list shows Eremex editors associated with common data types:
- Boolean values —
CheckEditor
- Double values —
SpinEditor
- Enumeration values —
ComboBoxEditor
- Properties with a
TypeConverter
attribute whoseTypeConverter.GetStandardValuesSupported
method returnstrue
—ComboBoxEditor
- Other values —
TextEditor
You can explicitly specify cell editors for DataGrid columns to override the default editor assignment, and to customize settings of in-place editors. The following sections provide more details about assigning editors.
When an edit operation starts in a cell, you can access and modify the active in-place editor. See the Access the Active In-place Eremex Editor section for more information.
Assign In-place Eremex Editors
To explcitly assign an in-place Eremex editor to cells (columns), use the GridColumn.EditorProperties
property.
You can set the EditorProperties
property to the following objects that specify the in-place editor type (all of these objects are BaseEditorProperties
descendants):
ButtonEditorProperties
— Contains settings specific to theButtonEditor
control.CheckEditorProperties
— Contains settings specific to theCheckEditor
control.ComboBoxEditorProperties
— Contains settings specific to theComboBoxEditor
control.DateEditorProperties
— Contains settings specific to theDateEditor
control.HyperlinkEditorProperties
— Contains settings specific to theHyperlinkEditor
control.MemoEditorProperties
— Contains settings specific to theMemoEditor
control.PopupColorEditorProperties
— Contains settings specific to thePopupColorEditor
control.SegmentedEditorProperties
— Contains settings specific to theSegmentedEditor
control.SpinEditorProperties
— Contains settings specific to theSpinEditor
control.TextEditorProperties
— Contains settings specific to theTextEditor
control.
Assume that you set the EditorProperties
property to a SpinEditorProperties
object. In display mode (cell editing is not active), the DataGrid control emulates a SpinEditor
in the target column's cells, using the settings of the SpinEditorProperties
object. No real SpinEditor
is created until an edit operation starts in a cell. When a user starts cell editing, the DataGrid control creates a real SpinEditor
in-place editor in the focused cell. After the edit operation is complete, the control destroys the real SpinEditor
and starts emulating a SpinEditor
in this cell. See Access the Active In-place Eremex Editor to learn how to access the real cell editor.
Example - How to use ButtonEditor as an in-place editor in a DataGrid column
The following code assigns a ButtonEditor
in-place editor to a DataGrid column.
xmlns:mxdg="https://schemas.eremexcontrols.net/avalonia/datagrid"
xmlns:mxe="https://schemas.eremexcontrols.net/avalonia/editors"
<mxdg:DataGridControl.Columns>
<mxdg:GridColumn Header="Name" FieldName="Name">
<mxdg:GridColumn.EditorProperties>
<mxe:ButtonEditorProperties>
<mxe:ButtonEditorProperties.Buttons>
<mxe:ButtonSettings Content="Clear"
Command="{Binding
$parent[mxdg:CellControl].DataControl.DataContext.ClearValueCommand}"/>
</mxe:ButtonEditorProperties.Buttons>
</mxe:ButtonEditorProperties>
</mxdg:GridColumn.EditorProperties>
</mxdg:GridColumn>
</mxdg:DataGridControl.Columns>
Assign In-place Eremex Editors Using Templates
You can use templates to assign Eremex editors to DataGrid columns. Use the GridColumn.CellTemplate
property for this purpose.
Set the x:Name
property to "PART_Editor" for the Eremex editor defined in a template. This ensures automatic binding of the editor's value (BaseEditor.EditorValue
) to the column's field. Additionally,
the editor's appearance settings (border visibility and foreground colors in the active and inactive states) will be managed by the DataGrid control.
xmlns:mxdg="https://schemas.eremexcontrols.net/avalonia/datagrid"
xmlns:mxe="https://schemas.eremexcontrols.net/avalonia/editors"
...
<mxdg:GridColumn Header="Phone" FieldName="Phone">
<mxdg:GridColumn.CellTemplate>
<DataTemplate>
<mxe:ButtonEditor x:Name="PART_Editor">
<mxe:ButtonEditor.Buttons>
<mxe:ButtonSettings Content="..."/>
</mxe:ButtonEditor.Buttons>
</mxe:ButtonEditor>
</DataTemplate>
</mxdg:GridColumn.CellTemplate>
</mxdg:GridColumn>
Custom Editors
You can specify custom editors for DataGrid columns using the following approaches:
- Assign an editor directly to a specific column.
- Dynamically assign editors to columns based on the data type of the column's underlying object.
See the Custom Editors topic for more information.
Get and Set Cell Values
Use the following API to obtain and set cell values:
DataGridControl.GetCellValue
DataGridControl.SetCellValue
Access the Active In-place Eremex Editor
When in-place Eremex editors are assigned to DataGrid columns (implicitly, or explicitly using the EditorSettings
property and templates), the control emulates the specified in-place editors in column cells in display mode (when cell editing is not active). No real in-place editor currently exists. The emulation of in-place editors in cells in display mode improves application performance.
When a user starts editing a cell, the control creates a real in-place editor. Use the DataGrid control's ActiveEditor
property to access the real Eremex editor instance that currently exists. When a cell loses focus, the real editor is destroyed, and the ActiveEditor
property returns null
.
Handle the ShowingEditor
event to receive notifications when edit operations start in cells. You can safely access the ActiveEditor
property in your ShowingEditor
event handler.
Disable Editor Activation
To prevent a cell editor from being activated in specific cases, you can handle the ShowingEditor
event and set the event handler's Cancel
parameter to true
.