View Code
protected override DevExpress.XtraGrid.Columns.GridColumnCollection CreateColumnCollection() { return new MyGridColumnCollection(this); } protected override DevExpress.XtraGrid.Columns.ColumnFilterInfo CreateFilterRowInfo(DevExpress.XtraGrid.Columns.GridColumn column, object _value) { try { if (SetAutoFilter)//是否允许用户模糊查询 { if ((column) is MyGridColumn && ((MyGridColumn)column).UseAdvancedFiltering == true && (string)_value != "") { string FilterText = (string)_value; if (FilterText.Contains("%") == false && FilterText.Contains("_") == false) { FilterText = String.Format("%{0}%", _value); } return new DevExpress.XtraGrid.Columns.ColumnFilterInfo(DevExpress.XtraGrid.Columns.ColumnFilterType.AutoFilter, _value, new DevExpress.Data.Filtering.BinaryOperator(column.FieldName, FilterText, DevExpress.Data.Filtering.BinaryOperatorType.Like), null); } else { return base.CreateFilterRowInfo(column, _value); } } else { return base.CreateFilterRowInfo(column, _value); } } catch (Exception) { return base.CreateFilterRowInfo(column, _value); } }
以上代码结合 http://www.cnblogs.com/freexiaoyu/archive/2012/09/19/2693925.html 文章放到MyGridView类中
View Code
public class MyGridColumn : DevExpress.XtraGrid.Columns.GridColumn { public MyGridColumn() : base() { } private bool mUseAdvancedFiltering = true; public bool UseAdvancedFiltering { get { return this.mUseAdvancedFiltering; } set { this.mUseAdvancedFiltering = value; } } } public class MyGridColumnCollection : GridColumnCollection { public MyGridColumnCollection(DevExpress.XtraGrid.Views.Base.ColumnView View) : base(View) { } protected override DevExpress.XtraGrid.Columns.GridColumn CreateColumn() { return new MyGridColumn(); } }