自定义GridControl编辑器

时间:2024-11-07 19:36:44

本文版权归博主 惊梦无痕 所有,欢迎转载,但须保留此段声明,并给出原文链接,谢谢合作。SourceLink

鉴于网上的针对GridControl的一些代码比较凌乱,且功能分散,故将整理过的代码分享出来。
本代码用的DevExpress版本号:17.2.6.0,旧的版本可能有些地方会有些微的变化。
目前该自定义编辑器中集成了一些比较实用的功能,希望对使用或正在学习DevExpress的同学有所帮助。
等下次有时间再把其他的一些自定义通用控件也发出来。

 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using Comteck.Winforms.Controls.Components;
using Comteck.Winforms.Utils;
using DevExpress.Data.Filtering;
using DevExpress.Utils;
using DevExpress.Utils.Serializing;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Registrator;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Base.Handler;
using DevExpress.XtraGrid.Views.Base.ViewInfo;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Views.Grid.Drawing;
using DevExpress.XtraGrid.Views.Grid.ViewInfo; namespace Comteck.Winforms.Controls {
#region MyGridControl /// <summary>
/// A grid view is represented by several classes.
/// Please make sure that you inherit the appropriate class to implement a specific functionality:
/// GridView - a central grid view class, which manages columns, view infos, a painter, mouse and keyboard handlers.
/// GridHandler - processes the mouse and keyboard.
/// GridViewInfo - calculates view information for drawing a grid view on screen.
/// GridViewPrintInfo - calculates the information necessary to print a grid view.
///
/// Assume, you have created a GridView descendant and want to use your class with the GridControl at design time.
/// You should do the following to register it:
/// 1. Create a Registrator class (please see GridInfoRegistrator in ViewRegistrator.cs).
/// Please note: you will need to be careful when overriding the ViewName property,
/// because it is used to identify the view within the GridControl's descendant.
/// Please make certain that you are using the same view name both in the registrator's ViewName property
/// and within the GridControl's CreateDefaultView overridden method.
/// 2. Inherit the GridControl class and override the RegisterAvailableViewsCore
/// method (it was the RegisterAvailableViews method in XtraGrid 2).
/// 3. If you want the GridControl to create an instance of your GridView by default,
/// you should override the GridControl.CreateDefaultView method.
///
/// 创建自定义的MyGridControl
/// <para>https://www.devexpress.com/Support/Center/Search/List/1?searchString=treelist</para>
/// <para>http://www.dxper.net/thread-555-1-1.html</para>
/// </summary>
[ToolboxItem(true)]
public class MyGridControl : GridControl {
/// <summary>
/// Create a new MyGridControl object
/// </summary>
public MyGridControl()
: base() {
// 使用内置的分页
this.CustomInit();
} /// <summary>
/// 创建初始化的GridView视图(请参照第3点)
/// </summary>
/// <returns></returns>
protected override BaseView CreateDefaultView() {
return base.CreateView("MyGridView");
} /// <summary>
/// 向容器中注册所有的控件
/// </summary>
/// <param name="collection"></param>
protected override void RegisterAvailableViewsCore(InfoCollection collection) {
base.RegisterAvailableViewsCore(collection);
collection.Add(new MyGridViewInfoRegistrator());
collection.Add(new MyBandedGridInfoRegistrator());
} /// <summary>
/// 初始化内置的分页,如果要使用增、删、改功能,则把下面的代码注释即可
/// </summary>
private void InitNagigator() {
this.EmbeddedNavigator.TextStringFormat = "记录 {0} / {1}";
this.EmbeddedNavigator.Buttons.Append.Visible = false;
this.EmbeddedNavigator.Buttons.Remove.Visible = false;
this.EmbeddedNavigator.Buttons.Edit.Visible = false;
this.EmbeddedNavigator.Buttons.EndEdit.Visible = false;
this.EmbeddedNavigator.Buttons.CancelEdit.Visible = false;
} private void CustomInit() {
this.InitNagigator();
}
} #endregion #region 创建自定义的GridView /// <summary>
/// 创建自定义的GridView
/// </summary>
public class MyGridView : GridView {
/// <summary>
/// DevExpress选择列的默认fieldname
/// </summary>
public const string DEVEXPRESS_SELECTION_NAME = "DX$CheckboxSelectorColumn";
/// <summary>
/// 当光标在末行最后一个指定字段时继续回车的跳转方式
/// </summary>
public enum EnumForwardType {
[Description("跳转到首行首列")]
Circle = ,
[Description("停止跳转,直接返回")]
Stop = ,
[Description("新增一行,光标定位到新行指定列")]
NewRow = ,
} /// <summary>
/// Default View Name
/// </summary>
protected override string ViewName => "MyGridView"; public delegate void AddNewLineDelegate();
/// <summary>
/// 新增行自定义事件
/// </summary>
public AddNewLineDelegate AddNewLineEventHandler; #region 自定义属性 //
// 摘要:
// 当 GridView 没有数据时是否显示提示,提示的值由 EmptyForegroundText 属性设置
[DefaultValue(false),]
[DXCategory("自定义属性")]
[Description("当 GridView 没有数据时是否显示提示,提示的值由 EmptyForegroundText 属性设置")]
[XtraSerializableProperty]
public virtual bool EnableShowEmptyForeground { get; set; }
//
// 摘要:
// 当 GridView 没有数据时的默认提示.
[DefaultValue(typeof(string), "")]
[DXCategory("自定义属性")]
[Description("当 GridView 没有数据时显示的值,默认显示\"没有查询到你所想要的数据!\"")]
[XtraSerializableProperty]
public virtual string EmptyForegroundText { get; set; }
//
// 摘要:
// GridView 回车时按指定字段跳转到相应的单元格.
// 调用方法如:new List<string>() { "SKUCODE", "PRICE", "DESCRIPTION" };
[DefaultValue(typeof(List<string>), "")]
[DXCategory("自定义属性")]
[Description("指定可以跳转的列(FieldName),回车时按值先后顺序跳转")]
[XtraSerializableProperty]
[TypeConverter(typeof(CollectionConverter))]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Browsable(false)]
public virtual List<string> ForwardColumnList { get; set; }
//
// 摘要:
// 当光标在末行最后一个指定字段时继续回车的跳转方式.
[DefaultValue(typeof(EnumForwardType), "Circle")]
[DXCategory("自定义属性")]
[Description("当光标在末行最后一个指定字段时继续回车的跳转方式")]
[XtraSerializableProperty]
public virtual EnumForwardType ForwardType { get; set; } = EnumForwardType.Circle;
//
// 摘要:
// 当末行最后一列回车新增行时,指定光标在新行定位的列(FieldName).
[DefaultValue(typeof(string), "")]
[DXCategory("自定义属性")]
[Description("当末行最后一列回车新增行时,指定光标在新行定位的列(FieldName),默认为新增行首个可编辑列")]
[XtraSerializableProperty]
public virtual string LocatedColumn { get; set; } #endregion #region 构造函数 /// <summary>
/// 默认构造
/// </summary>
public MyGridView() {
this.OptionsFilter.ColumnFilterPopupMode = DevExpress.XtraGrid.Columns.ColumnFilterPopupMode.Classic;
} /// <summary>
/// 含参构造
/// </summary>
/// <param name="grid"></param>
public MyGridView(GridControl ownerGrid)
: base(ownerGrid) {
this.OptionsFilter.ColumnFilterPopupMode = DevExpress.XtraGrid.Columns.ColumnFilterPopupMode.Classic;
} #endregion #region 自定义方法 /// <summary>
/// 初始化,设置默认值
/// </summary>
public void Initialize() {
// 设置为多选
this.OptionsSelection.MultiSelect = true;
// 自带勾选列的宽度
this.OptionsSelection.CheckBoxSelectorColumnWidth = ;
// 选中序号列是否勾选
this.OptionsSelection.UseIndicatorForSelection = false;
// 隐藏提示
this.OptionsView.ShowGroupPanel = false;
// 是否自适应列宽度
this.OptionsView.ColumnAutoWidth = false;
// 是否启用偶数行外观
this.OptionsView.EnableAppearanceEvenRow = true;
// 是否启用奇数行外观
this.OptionsView.EnableAppearanceOddRow = true;
// 是否显示过滤面板
this.OptionsView.ShowFilterPanelMode = ShowFilterPanelMode.Never;
// 是否显示子报表
this.OptionsDetail.EnableMasterViewMode = false;
// 筛选模式
this.OptionsFilter.ColumnFilterPopupMode = DevExpress.XtraGrid.Columns.ColumnFilterPopupMode.Classic;
// 编辑模式
this.OptionsBehavior.EditorShowMode = EditorShowMode.MouseUp;
// 打印效果
this.OptionsPrint.AutoWidth = false;
// 字段标题居中
this.Appearance.HeaderPanel.TextOptions.HAlignment = HorzAlignment.Center;
// 选中行颜色
this.SetAppearanceColor();
// 是否回车后光标移到下一个单元格
this.OptionsNavigation.EnterMoveNextColumn = true;
// 是否允许移动列
this.OptionsCustomization.AllowColumnMoving = false;
// 默认选中第一行
this.FocusedRowHandle = ;
// 设置行号宽度
this.IndicatorWidth = ;
} /// <summary>
/// 设置单元格是否可编辑
/// </summary>
/// <param name="editableColumnsList">当GridView可编辑时,指定可以编辑的列(FieldName).</param>
public void SetEditableColumns(List<string> editableColumnsList) {
if (this.OptionsBehavior.Editable && editableColumnsList != null && editableColumnsList.Count > ) {
foreach (GridColumn col in this.Columns) {
if (editableColumnsList.Exists(x => x == col.FieldName)) {
// 设置标题字体色
col.AppearanceHeader.ForeColor = Color.Blue;
col.OptionsColumn.AllowEdit = true;
} else {
// 设置标题字体色
col.AppearanceHeader.ForeColor = Color.Black;
col.OptionsColumn.AllowEdit = false;
}
}
}
} /// <summary>
/// 判断是否为表格最后一列可编辑列
/// </summary>
/// <param name="view"></param>
/// <param name="focusedColumn"></param>
/// <returns></returns>
private bool IsLastEditableColumn(GridColumn focusedColumn) {
var index = this.VisibleColumns.IndexOf(focusedColumn); for (int i = this.VisibleColumns.Count - ; i >= ; i--) {
GridColumn column = this.VisibleColumns[i];
// 忽略不可编辑Column
if (!column.OptionsColumn.AllowEdit) continue;
// 当前列如果是最后一列可编辑列,则返回True,否则返回False
return index == i;
}
// 如果都不可编辑,则返回False
return false;
} /// <summary>
/// 添加新行
/// </summary>
private void AddNewLine() {
var list = this.GridControl.DataSource;
// 获取当前实例的 Type
var t = this.DataSource.GetType();
// 动态创建实例
var obj = Activator.CreateInstance(t.GetGenericArguments()[]);
// 调用公用方法 Add
var method = t.GetMethod("Add");
// 将构建好的实例添加到数据源中
method.Invoke(list, new object[] { obj });
// 刷新数据源
this.RefreshData();
} /// <summary>
/// 获取GridView过滤或排序后的数据集
/// </summary>
/// <typeparam name="T">泛型对象</typeparam>
/// <returns></returns>
public IEnumerable<T> GetFilteredDataSource<T>() where T : class {
var list = new List<T>();
for (int i = ; i < this.RowCount; i++) {
if (this.IsGroupRow(i)) continue; var entity = this.GetRow(i) as T;
if (entity == null) continue; list.Add(entity);
}
return list;
} /// <summary>
/// 获取GridView的选中行数据集(数据源是 DataTable)
/// </summary>
/// <returns></returns>
public DataTable GetSelectedDataRows() {
var dt = (this.DataSource as DataView).Table.Clone();
var rowIds = this.GetSelectedRows(); foreach (var id in rowIds) {
var row = (this.GetRow(id) as DataRowView).Row;
if (row == null) continue; dt.Rows.Add(row.ItemArray);
}
return dt;
} #endregion /// <summary>
/// 在初始化后注册一些事件
/// </summary>
public override void EndInit() {
base.EndInit(); // 针对MyGridLookUpEdit的情况
if (string.IsNullOrWhiteSpace(this.GridControl?.Name)) return; // 设置行号
this.CustomDrawRowIndicator += new RowIndicatorCustomDrawEventHandler(MyGridView_CustomDrawRowIndicator);
// 设置行号宽度
this.RowCountChanged += new EventHandler(MyGridView_RowCountChanged);
// 在查询得到0条记录时显示自定义的字符提示/显示
this.CustomDrawEmptyForeground += new CustomDrawEventHandler(MyGridView_CustomDrawEmptyForeground);
// 回车跳转单元格(配合 ForwardColumnList 使用)
this.KeyDown += new KeyEventHandler(MyGridView_KeyDown);
} /// <summary>
/// 设置自动行号
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MyGridView_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e) {
if (e.Info.IsRowIndicator && e.RowHandle >= ) {
e.Info.DisplayText = (e.RowHandle + ).ToString();
}
} /// <summary>
/// 行号宽度随行数的变化而变化
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MyGridView_RowCountChanged(object sender, EventArgs e) {
// 根据总行数设置行号宽度
this.IndicatorWidth = + (this.RowCount.ToString().Length - ) * ;
} /// <summary>
/// 在查询得到0条记录时显示自定义的字符提示/显示
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MyGridView_CustomDrawEmptyForeground(object sender, CustomDrawEventArgs e) {
if (!this.EnableShowEmptyForeground) return; string showText = string.IsNullOrWhiteSpace(this.EmptyForegroundText) ? "没有查询到你所想要的数据!" : this.EmptyForegroundText; //方法一(此方法为GridView设置了数据源绑定时,可用)
try {
var bindingSource = this.DataSource as BindingSource;
if (bindingSource.Count == ) {
var str = showText;
var f = new Font("宋体", , FontStyle.Bold);
var r = new Rectangle(e.Bounds.Top + , e.Bounds.Left + , e.Bounds.Right - , e.Bounds.Height - );
e.Graphics.DrawString(str, f, Brushes.Black, r);
}
} catch {
//方法二(此方法为GridView没有设置数据源绑定时使用,一般使用此种方法)
if (this.RowCount == ) {
var str = showText;
var f = new Font("宋体", , FontStyle.Bold);
var r = new Rectangle(e.Bounds.Left + , e.Bounds.Top + , e.Bounds.Width - , e.Bounds.Height - );
e.Graphics.DrawString(str, f, Brushes.Black, r);
}
}
} #region 单元格回车事件 /// <summary>
/// 默认情况下,回车或Tab按可编辑列跳转
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnDefaultKeyDown(object sender, KeyEventArgs e) {
if (!((e.KeyCode == Keys.Enter && this.OptionsNavigation.EnterMoveNextColumn) || e.KeyCode == Keys.Tab)) return; GridColumn column = null;
var index = this.VisibleColumns.IndexOf(this.FocusedColumn); // 光标是否在最后一列可编辑列
if (IsLastEditableColumn(this.FocusedColumn)) {
#region 判断是否到达末行 if (this.FocusedRowHandle >= this.RowCount - ) {
// 此处可选择跳转到首行或者直接返回或者新增行
switch (this.ForwardType) {
case EnumForwardType.Circle: // 首行首列
this.MoveFirst();
for (int i = ; i < this.VisibleColumns.Count; i++) {
column = this.VisibleColumns[i];
// 忽略不可编辑Column
if (!column.OptionsColumn.AllowEdit) continue;
// 当前列可编辑,则光标定位到该列
this.FocusedColumn = column;
return;
}
break;
case EnumForwardType.Stop: // 停止跳转,直接返回
e.Handled = true;
break;
case EnumForwardType.NewRow: // 新增行,并跳转到新行首列
if (this.AddNewLineEventHandler == null)
AddNewLine();
else
AddNewLineEventHandler(); this.MoveNext();
// 没有指定定位字段
if (string.IsNullOrWhiteSpace(this.LocatedColumn)) {
for (int i = ; i < this.VisibleColumns.Count; i++) {
column = this.VisibleColumns[i];
// 忽略不可编辑Column
if (!column.OptionsColumn.AllowEdit) continue;
// 当前列可编辑,则光标定位到该列
this.FocusedColumn = column;
return;
}
} else {
this.FocusedColumn = this.Columns[this.LocatedColumn];
}
break;
}
return;
} #endregion this.MoveNext();
for (int i = ; i < this.VisibleColumns.Count; i++) {
column = this.VisibleColumns[i];
// 忽略不可编辑Column
if (!column.OptionsColumn.AllowEdit) continue;
// 如果是系统自带的编辑列,则直接跳过
if (column.FieldName == DEVEXPRESS_SELECTION_NAME) continue; // 当前列可编辑,则光标定位到该列
this.FocusedColumn = column;
return;
}
} else {
// 从当前定位列跳转到下一可编辑列
for (int i = index + ; i < this.VisibleColumns.Count; i++) {
column = this.VisibleColumns[i];
// 忽略不可编辑Column
if (!column.OptionsColumn.AllowEdit) continue;
// 如果是系统自带的编辑列,则直接跳过
if (column.FieldName == DEVEXPRESS_SELECTION_NAME) continue; // 当前列可编辑,则光标定位到该列
this.FocusedColumn = column;
return;
} // 如果光标在不可编辑列
for (int i = ; i <= index; i++) {
column = this.VisibleColumns[i];
// 忽略不可编辑Column
if (!column.OptionsColumn.AllowEdit) continue;
// 如果是系统自带的编辑列,则直接跳过
if (column.FieldName == DEVEXPRESS_SELECTION_NAME) continue; // 当前列可编辑,则光标定位到该列
this.FocusedColumn = column;
return;
}
}
} /// <summary>
/// 自定义跳转,按指定列字段跳转
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnCustomerKeyDown(object sender, KeyEventArgs e) {
if (!((e.KeyCode == Keys.Enter && this.OptionsNavigation.EnterMoveNextColumn) || e.KeyCode == Keys.Tab)) return; var fieldName = this.FocusedColumn.FieldName; if (this.ForwardColumnList.Contains(fieldName)) {
var index = this.ForwardColumnList.IndexOf(fieldName); // 光标不在当前行指定列集合的最后一列
if (index != this.ForwardColumnList.Count - ) {
this.FocusedColumn = this.Columns[this.ForwardColumnList[index + ]];
} else // 光标定位当前行指定列集合的最后一列
{
#region 判断是否到达末行 if (this.FocusedRowHandle >= this.RowCount - ) {
// 此处可选择跳转到首行或者直接返回或者新增行
switch (this.ForwardType) {
case EnumForwardType.Circle: // 首行首列
this.MoveFirst();
this.FocusedColumn = this.Columns[this.ForwardColumnList[]];
break;
case EnumForwardType.Stop: // 停止跳转,直接返回
e.Handled = true;
break;
case EnumForwardType.NewRow: // 新增行,并跳转到新行首列
if (this.AddNewLineEventHandler == null)
AddNewLine();
else
AddNewLineEventHandler(); fieldName = string.IsNullOrWhiteSpace(this.LocatedColumn) ? this.ForwardColumnList[] : this.LocatedColumn; this.MoveNext();
this.FocusedColumn = this.Columns[fieldName];
break;
}
return;
} #endregion this.MoveNext();
this.FocusedColumn = this.Columns[this.ForwardColumnList[]];
}
} else {
this.FocusedColumn = this.Columns[this.ForwardColumnList[]];
}
} /// <summary>
/// 回车跳转单元格
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MyGridView_KeyDown(object sender, KeyEventArgs e) {
if (!((e.KeyCode == Keys.Enter && this.OptionsNavigation.EnterMoveNextColumn) || e.KeyCode == Keys.Tab)) return; if (this.ValidateEditor() == false) {
return;
} // 未设置,则按默认规则跳转
if (this.ForwardColumnList == null || this.ForwardColumnList.Count == ) {
OnDefaultKeyDown(sender, e);
} else {
OnCustomerKeyDown(sender, e);
}
} #endregion #region GridLookUpEdit 模糊匹配 /// <summary>
/// SetGridControlAccessMethod,主要是了MyGridLookUpEdit用
/// </summary>
/// <param name="newControl"></param>
protected internal virtual void SetGridControlAccessMethod(GridControl newControl) {
SetGridControl(newControl);
} /// <summary>
/// GridLookUpEdit的模糊匹配
/// </summary>
/// <param name="text"></param>
/// <param name="displayMember"></param>
/// <returns></returns>
protected override string OnCreateLookupDisplayFilter(string text, string displayMember) {
var subStringOperators = new List<CriteriaOperator>();
foreach (var sString in text.Split(' ')) {
var columnsOperators = new List<CriteriaOperator>(); foreach (GridColumn col in this.Columns) {
columnsOperators.Add(new FunctionOperator(FunctionOperatorType.Contains, new OperandProperty(col.FieldName), sString));
} subStringOperators.Add(new GroupOperator(GroupOperatorType.Or, columnsOperators));
} return new GroupOperator(GroupOperatorType.And, subStringOperators).ToString();
} /// <summary>
/// 模糊匹配的字符串
/// </summary>
protected virtual internal string GetExtraFilterText => base.ExtraFilterText; #endregion #region 重写属性 /// <summary>
///
/// </summary>
/// <returns></returns>
protected override ColumnViewOptionsView CreateOptionsView() {
return new CustomGridOptionsView();
} #endregion
} #endregion #region MyGridHandler processes the mouse and keyboard. /// <summary>
/// processes the mouse and keyboard.
/// </summary>
public class MyGridHandler : DevExpress.XtraGrid.Views.Grid.Handler.GridHandler {
/// <summary>
/// Constructor
/// </summary>
/// <param name="gridView"></param>
public MyGridHandler(GridView gridView)
: base(gridView) {
} /// <summary>
/// 重写事件 OnKeyDown
/// </summary>
/// <param name="e"></param>
protected override void OnKeyDown(KeyEventArgs e) {
try {
base.OnKeyDown(e);
} catch { } // Ctrl + C 复制单元格
if (e.Control & e.KeyCode == Keys.C) {
try {
Clipboard.SetDataObject(this.View.GetFocusedRowCellDisplayText(this.View.FocusedColumn));
e.Handled = true;
} catch { }
}
}
} #endregion #region MyGridViewInfoRegistrator /// <summary>
/// GridInfoRegistrator,注册MyGridView
/// </summary>
public class MyGridViewInfoRegistrator : GridInfoRegistrator {
protected const string MyGridViewName = "MyGridView"; /// <summary>
/// Default View Name
/// </summary>
public override string ViewName => MyGridViewName; /// <summary>
/// 创建GridView
/// </summary>
/// <param name="grid"></param>
/// <returns></returns>
public override BaseView CreateView(GridControl grid) {
// 主要为了GridLookUpEdit用
var view = new MyGridView();
view.SetGridControlAccessMethod(grid);
view.Initialize();
return view;
} /// <summary>
/// CreateViewInfo
/// </summary>
/// <param name="view"></param>
/// <returns></returns>
public override BaseViewInfo CreateViewInfo(BaseView view) {
return new MyGridViewInfo(view as MyGridView);
} /// <summary>
/// 创建自定义的事件
/// </summary>
/// <param name="view"></param>
/// <returns></returns>
public override BaseViewHandler CreateHandler(BaseView view) {
return new MyGridHandler(view as MyGridView);
} /// <summary>
/// 创建自定义的绘画
/// </summary>
/// <param name="view"></param>
/// <returns></returns>
public override BaseViewPainter CreatePainter(BaseView view) {
return new MyGridPainter(view as GridView);
}
} #endregion #region MyGridViewInfo calculates view information for drawing a grid view on screen. /// <summary>
/// calculates view information for drawing a grid view on screen.
/// </summary>
public class MyGridViewInfo : GridViewInfo {
/// <summary>
/// Constructor
/// </summary>
/// <param name="gridView"></param>
public MyGridViewInfo(GridView gridView)
: base(gridView) { }
} #endregion #region GridPainter /// <summary>
/// 自定义画笔
/// </summary>
public class MyGridPainter : GridPainter {
/// <summary>
/// Constructor
/// </summary>
/// <param name="view"></param>
public MyGridPainter(GridView view) : base(view) { } /// <summary>
/// 创建视图
/// </summary>
public virtual new MyGridView View => (MyGridView)base.View; /// <summary>
/// 绘制行信息,主要为了MyGridLookUpEdit
/// </summary>
/// <param name="e"></param>
/// <param name="cell"></param>
protected override void DrawRowCell(GridViewDrawArgs e, GridCellInfo cell) {
cell.ViewInfo.MatchedStringUseContains = true;
// 匹配表达式
cell.ViewInfo.MatchedString = this.View.GetExtraFilterText;
// 单元格状态
cell.State = GridRowCellState.Dirty;
// 更新行
e.ViewInfo.UpdateCellAppearance(cell);
// Draw
base.DrawRowCell(e, cell);
}
} #endregion
}