一.关于ListEditor
ListEditor是ListView的可视化体现。ListEditor拥有一个Control,该Control的作用是显示ListView的对象集合。ListEditor管理该Control,负责Control的创建,数据绑定和管理Control与ListView之间的交互。
从现有View获取ListEditor及其Control:
ListEditor editor=((ListView)View).Editor;
//若该ListEditor的control是GridControl,使用ListEditor.Control属性获取该Control
GridControl gc=(GridControl)editor.Control;
若要实现自定义的ListEditor,必须用ListEditorAttribute特性标记该自定义的类。
二.自定义ListEditor(该例来自于http://documentation.devexpress.com/#Xaf/CustomDocument2659 )
我们准备为一个图片类型实现自定义ListEditor,在Solution.Module中声明该接口。
using System.Drawing;
interface IPictureItem {
Image Image { get; }
string Text { get; }
string ID { get; }
}
然后在Solution.Module.Win中实现自定义的ListEditor类
/*Typical implementation of the ListEditor class' descendants comprises the following steps:
1.Override the CreateControlsCore method. Create and configure an instance of the control that will represent a List View in a UI. Handle the control's events to call the following methods:
- OnProcessSelectedItem
- OnSelectionChanged
- OnFocusedObjectChanging
- OnFocusedObjectChanged
- OnNewObjectAdding
- OnNewObjectCanceled
- OnNewObjectCreated
2.Override the AssignDataSourceToControl method. Assign the List Editor's data source to its control.
3.Override the Refresh method. Refresh data in the List Editor's control.
4.Override the RequiredProperties property. Return business class' property names that are used by the List Editor when displaying objects. These properties are treated as displayable if a List View's data source is derived from the XPBaseCollection.
5.Override the SelectionType property. Return the selection type supported by the List Editor's control.
6.Override the GetSelectedObjects method. Return a list of the selected objects.
7.Override the FocusedObject method. Get and set the control's focused object.
8.If the custom List Editor does not support server mode (CollectionSourceBase.IsServerMode), override the IsServerModeSupported property and set it to false. It is also recommended that you implement a custom generator updater to disable server mode for List Views