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="clr-namespace:Eremex.AvaloniaUI.Controls.TreeList;assembly=Eremex.Avalonia.Controls"
xmlns:mxe="clr-namespace:Eremex.AvaloniaUI.Controls.Editors;assembly=Eremex.Avalonia.Controls"
<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="clr-namespace:Eremex.AvaloniaUI.Controls.TreeList;assembly=Eremex.Avalonia.Controls"
xmlns:mxe="clr-namespace:Eremex.AvaloniaUI.Controls.Editors;assembly=Eremex.Avalonia.Controls"
<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="clr-namespace:Eremex.AvaloniaUI.Controls.TreeList;assembly=Eremex.Avalonia.Controls"
xmlns:mxe="clr-namespace:Eremex.AvaloniaUI.Controls.Editors;assembly=Eremex.Avalonia.Controls"
...
<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
When in-place Eremex editors are assigned to TreeList/TreeView columns (implicitly, or explicitly using the EditorSettings
property and templates), the controls emulate 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. You can use a TreeList/TreeView 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
.