Example E443
Visible to All Users

TreeListEditor - How to enable in-place editing in the WinForms tree List View

Files to look at:

This example shows how to implement a custom ViewController that gets access to the TreeList control and makes it editable according to the XtraTreeList documentation:
    WinForms Controls > Controls > Tree List > Feature Center > Data Editing
    TreeListOptionsBehavior.Editable Property
    TreeList.ShowingEditor Event
    TreeList.CellValueChanged Event
Take special note that this is not a complete solution and you will need to modify and test this example code further in other scenarios according to your business requirements. For instance, if you require supporting ConditionalAppearance rules, consider using the code from the Q479878 ticket. If you require supporting member-level security permissions, consider extending this example by analogy with the DevExpress.ExpressApp.Win.SystemModule.GridListEditorMemberLevelSecurityController class for GridListEditor.
Refer to the Tree List Editors - How to edit data directly in the tree view (inplace / inline modifications) thread to learn more about possible limitations and alternative solutions.

See also:
How to enable in-place editing in the ASP.NET tree List View (ASPxTreeListEditor)

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

EFCore/TreeListInplaceEF/TreeListInplaceEF.Win/Controllers/TreeListAppearanceControllerEx.cs
C#
using DevExpress.ExpressApp.Editors; using DevExpress.ExpressApp.TreeListEditors.Win; using DevExpress.ExpressApp.Win.Controls; using DevExpress.ExpressApp.Win.Editors; using DevExpress.XtraTreeList; namespace WinSolution.Module.Win { public class TreeListAppearanceControllerEx : TreeListAppearanceController { protected override void OnTreeListChanged() { base.OnTreeListChanged(); if (base.Active.ResultValue && base.View != null && base.View.Editor != null && base.View.Editor is TreeListEditor && ((TreeListEditor)base.View.Editor).TreeList != null) { ((TreeListEditor)base.View.Editor).TreeList.ShowingEditor += new System.ComponentModel.CancelEventHandler(control_ShowingEditor); } } void control_ShowingEditor(object sender, System.ComponentModel.CancelEventArgs e) { TreeList tl = (TreeList)sender; ObjectTreeListNode node = tl.FocusedNode as ObjectTreeListNode; if (node == null) return; this.OnCustomizeAppearance(new CustomizeAppearanceEventArgs(tl.FocusedColumn.FieldName, "ViewItem", new GridViewCancelEventArgsAppearanceAdapter(null, e), node.Object, null)); } } }
EFCore/TreeListInplaceEF/TreeListInplaceEF.Win/Controllers/TreeListInplaceEditViewController.cs
C#
using System; using DevExpress.ExpressApp; using DevExpress.XtraTreeList; using DevExpress.ExpressApp.DC; using DevExpress.ExpressApp.Model; using DevExpress.ExpressApp.Win.Core; using DevExpress.XtraEditors.Repository; using DevExpress.ExpressApp.Win.Controls; using DevExpress.ExpressApp.TreeListEditors.Win; using DevExpress.Persistent.BaseImpl.EF; namespace WinSolution.Module.Win { public class TreeListInplaceEditViewController : ViewController<ListView> { protected override void OnActivated() { base.OnActivated(); TreeListEditor treeListEditor = View.Editor as TreeListEditor; if (treeListEditor != null) { treeListEditor.AllowEditChanged += treeListEditor_AllowEditChanged; if (treeListEditor.TreeList != null) { UpdateEditableTreeList(treeListEditor); SubscribeToControlEvents(treeListEditor.TreeList); } treeListEditor.ControlsCreated += treeListEditor_ControlsCreated; } } void treeListEditor_ControlsCreated(object sender, EventArgs e) { TreeListEditor treeListEditor = (TreeListEditor)sender; UpdateEditableTreeList(treeListEditor); SubscribeToControlEvents(treeListEditor.TreeList); } private void SubscribeToControlEvents(TreeList treeList) { treeList.CellValueChanged += treeList_CellValueChanged; treeList.ShownEditor += treeList_ShownEditor; } protected override void OnDeactivated() { TreeListEditor treeListEditor = View.Editor as TreeListEditor; if (treeListEditor != null) { treeListEditor.AllowEditChanged -= treeListEditor_AllowEditChanged; treeListEditor.ControlsCreated -= treeListEditor_ControlsCreated; ObjectTreeList treeList = (ObjectTreeList)treeListEditor.TreeList; if (treeList != null) { treeList.CellValueChanged -= treeList_CellValueChanged; treeList.ShownEditor -= treeList_ShownEditor; } } base.OnDeactivated(); } private void UpdateEditableTreeList(TreeListEditor treeListEditor) { ObjectTreeList treeList = treeListEditor.TreeList as ObjectTreeList; if (treeList != null) { treeList.OptionsBehavior.Editable = treeListEditor.AllowEdit; foreach (RepositoryItem ri in treeList.RepositoryItems) { ri.ReadOnly = !treeListEditor.AllowEdit; } foreach (TreeListColumnWrapper columnWrapper in treeListEditor.Columns) { IModelColumn modelColumn = View.Model.Columns[columnWrapper.PropertyName]; if (modelColumn != null) columnWrapper.Column.OptionsColumn.AllowEdit = modelColumn.AllowEdit; } treeList.OptionsBehavior.ImmediateEditor = true; } } void treeListEditor_AllowEditChanged(object sender, EventArgs e) { UpdateEditableTreeList((TreeListEditor)sender); } private void treeList_ShownEditor(object sender, EventArgs e) { ObjectTreeList treeList = (ObjectTreeList)sender; IGridInplaceEdit activeEditor = treeList.ActiveEditor as IGridInplaceEdit; if (activeEditor != null && treeList.FocusedObject is BaseObject) { activeEditor.GridEditingObject = treeList.FocusedObject; } } private void treeList_CellValueChanged(object sender, CellValueChangedEventArgs e) { if (!e.ChangedByUser) return; ObjectTreeList treeList = (ObjectTreeList)sender; object newValue = e.Value; if (e.Value is BaseObject) newValue = ObjectSpace.GetObject(e.Value); object focusedObject = treeList.FocusedObject; if (focusedObject != null) { IMemberInfo focusedColumnMemberInfo = ObjectSpace.TypesInfo.FindTypeInfo(focusedObject.GetType()).FindMember(e.Column.FieldName); if (focusedColumnMemberInfo != null) { focusedColumnMemberInfo.SetValue(focusedObject, newValue); } } } } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.