关键代码请参考
The current implementation doesn't provide interfaces to force the described feature to work automatically. However, in this article, we'll try to create a descendant and introduce the required behavior.
To accomplish this task, we'll have to create and descendants.
To force the drop-down grid to apply a proper filter condition, we need to override the OnCreateLookupDisplayFilter method. Here is some sample code:
public class CustomGridView : GridView{ public CustomGridView() : base() { } protected override string OnCreateLookupDisplayFilter(string text, string displayMember) { string exp = LikeData.CreateContainsPattern(text); string searchString = ""; foreach (GridColumn col in Columns) { if (col.Visible) searchString = searchString + new BinaryOperator(col.FieldName, exp, BinaryOperatorType.Like).ToString() + " Or "; } searchString = searchString.Substring(0, searchString.Length - 4); return searchString; } protected virtual internal string GetExtraFilterText { get { return ExtraFilterText; } }}
Additionally, it is necessary to highlight all found matches. To do this, we should override the view's painting mechanism. This can be done by creating our custom painter and by overriding the DrawRowCell method:
public class CustomGridPainter : GridPainter{ public CustomGridPainter(GridView view) : base(view) { } public virtual new CustomGridView View { get { return (CustomGridView)base.View; } } protected override void DrawRowCell(GridViewDrawArgs e, GridCellInfo cell) { cell.ViewInfo.MatchedStringUseContains = true; cell.ViewInfo.MatchedString = View.GetExtraFilterText; cell.State = GridRowCellState.Dirty; e.ViewInfo.UpdateCellAppearance(cell); base.DrawRowCell(e, cell); }}
Now you should properly register it, to make it available. Please refer to the article to learn more on how to accomplish this.
Finally you should create a descendant, an override the RepositoryItemGridLookUpEdit.CreateViewInstance and RepositoryItemGridLookUpEdit.CreateGrid methods.
The attached example contains descendants of the , GridPainter, , classes.
Additionally, there are and GridInfoRegistrator descendants for registering a custom grid view.See Also: