强大DevExpress,Winform LookUpEdit 实现多列查询 gridview弹出下拉选择 z

关键代码请参考http://www.devexpress.com/Support/Center/p/K18333.aspx

最新DEMO 下载  

The current GridLookUpEdit's implementation doesn't provide interfaces to force the described feature to work automatically. However, in this article, we'll try to create a GridLookUpEdit's descendant and introduce the required behavior.

To accomplish this task, we'll have to create GridLookUpEdit and GridView 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:

[C#] Open in popup window
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:

[C#] Open in popup window
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 How to create a GridView descendant class and register it for design-time use article to learn more on how to accomplish this.

Finally you should create a GridLookUpEdit descendant, an override the RepositoryItemGridLookUpEdit.CreateViewInstance and RepositoryItemGridLookUpEdit.CreateGrid methods.

The attached example contains descendants of the GridView, GridPainter, GridLookUpEdit, RepositoryItemGridLookUpEdit classes.
Additionally, there are GridControl and GridInfoRegistrator descendants for registering a custom grid view.

See Also:
How to create a GridView descendant class and register it for design-time use
Custom Editors

更多 0
 

转载于:https://www.cnblogs.com/zeroone/p/3606289.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值