Data Editing
Default In-place Eremex Editors
The default behavior of the TreeList and TreeView controls is to use in-place Eremex editors to display and edit cell values of common data types: If you do not explicitly specify cell editors, the TreeList and TreeView controls use in-place Eremex editors to display and edit cell values of 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 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
The TreeList and TreeView controls allow you to explicitly assign in-place Eremex editors to cells (columns) to override the default editor assignment, or to customize cell editors in XAML or code-behind. Use the following properties for this purpose:
TreeView control :
TreeViewControl.EditorProperties
The TreeView control displays a single column of data. Thus, the
TreeViewControl.EditorProperties
property specifies the in-place editor used to edit this column's cells.TreeList control:
TreeListColumn.EditorProperties
Each column in the TreeList control can have its own in-place editor. Create a TreeList column (a
TreeListColumn
object) in theTreeListControl.Columns
collection and set the column's editor using theTreeListColumn.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 TreeList/TreeView 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 TreeList/TreeView 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 treelist column
The following code assigns a ButtonEditor
in-place editor to a TreeList column.
xmlns:mxtl="https://schemas.eremexcontrols.net/avalonia/treelist"
xmlns:mxe="https://schemas.eremexcontrols.net/avalonia/editors"
<mxtl:TreeListControl.Columns>
<mxtl:TreeListColumn Header="Name" FieldName="Name">
<mxtl:TreeListColumn.EditorProperties>
<mxe:ButtonEditorProperties>
<mxe:ButtonEditorProperties.Buttons>
<mxe:ButtonSettings Content="Clear"
Command="{Binding $parent[mxtl:CellControl].DataControl.
DataContext.ClearValueCommand}"/>
</mxe:ButtonEditorProperties.Buttons>
</mxe:ButtonEditorProperties>
</mxtl:TreeListColumn.EditorProperties>
</mxtl:TreeListColumn>
</mxtl:TreeListControl.Columns>
Example - How to use ComboBoxEditor as an in-place editor in treeview
The following code assigns a ComboBoxEditor
in-place editor to a TreeView.
xmlns:mxtl="https://schemas.eremexcontrols.net/avalonia/treelist"
xmlns:mxe="https://schemas.eremexcontrols.net/avalonia/editors"
<mxtl:TreeViewControl.EditorProperties>
<mxe:ComboBoxEditorProperties ItemsSource="{Binding Families}"/>
</mxtl:TreeViewControl.EditorProperties>
Assign In-place Eremex Editors Using Templates
The TreeList and TreeView controls allow you to use templates to assign Eremex editors to columns. Use the following properties for this purpose:
TreeListColumn.CellTemplate
TreeViewControl.CellTemplate
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 TreeList/TreeView control.
xmlns:mxtl="https://schemas.eremexcontrols.net/avalonia/treelist"
xmlns:mxe="https://schemas.eremexcontrols.net/avalonia/editors"
...
<mxtl:TreeListColumn Header="Phone" FieldName="Phone">
<mxtl:TreeListColumn.CellTemplate>
<DataTemplate>
<mxe:ButtonEditor x:Name="PART_Editor">
<mxe:ButtonEditor.Buttons>
<mxe:ButtonSettings Content="..."/>
</mxe:ButtonEditor.Buttons>
</mxe:ButtonEditor>
</DataTemplate>
</mxtl:TreeListColumn.CellTemplate>
</mxtl:TreeListColumn>
Custom Editors
You can specify custom editors for cells in the TreeList and TreeView controls 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. This technique is applicable to the TreeList control.
See the Custom Editors topic for more information.
Get and Set Cell Values
The TreeList and TreeView controls expose the following API to obtain and set cell values:
TreeListControl.GetCellDisplayText
TreeListControl.GetCellValue
TreeListControl.SetCellValue
TreeViewControl.GetCellDisplayText
TreeViewControl.GetCellValue
TreeViewControl.SetCellValue
Access the Active In-place Eremex Editor
ActiveEditor
property — Returns the active in-place editor.When an in-place Eremex editor is assigned to a TreeList/TreeView column (implicitly, or explicitly using the
EditorSettings
property and templates), the control emulates the specified in-place editor in this column's cells in display mode (when cell editing is not active). No real in-place editor exists at this moment. The emulation of cell editors in display mode improves application performance.When a user starts editing a cell, the control creates a real in-place editor. At this moment, you can use the control's
ActiveEditor
property to access the real Eremex editor instance. When a cell loses focus, the real editor is destroyed, and theActiveEditor
property returnsnull
.ShowingEditor
event — Allows you to receive notifications when edit operations start in row cells. You can safely access theActiveEditor
property in aShowingEditor
event handler.
Show a Cell Editor
ShowEditor
method — Activates a cell editor in the focused cell.ShowingEditor
event — Allows you to prevent a cell editor from being activated by users in specific cases. While handling theShowingEditor
event, set theCancel
event parameter totrue
to disable an editor activation.
Close the Active In-place Editor
CloseEditor
method — Saves changes made in the cell editor and closes the editor.HideEditor
method — Closes the cell editor without saving any changes.HiddenEditor
event — Fires after the active cell editor is closed.
Save the Changes Made in an In-place Editor
CloseEditor
method — Saves changes made in the cell editor and closes the editor.PostEditor
method — Saves changes made in the active cell editor without closing the editor.