zoukankan      html  css  js  c++  java
  • Winforms平台界面开发技巧,如何快速掌握Filter Editor(二)

    下载DevExpress v19.2完整版

    DevExpress Winforms Controls 内置140多个UI控件和库,完美构建流畅、美观且易于使用的应用程序。想要体验?点击下载>>

    DevExpress WinForms安装附带两个允许最终用户构建过滤器查询的控件:提供GUI的Filter控件和将Filter控件与基于文本输入的面板组合在一起的Filter Editor控件。WinForms中,大多数数据感知控件都使用这些组件,但是您也可以将其包含在自己的表单中,并根据需要将其绑定到数据感知控件中。

    Registering函数

    自定义函数准备就绪后,您需要对其进行注册,即将其添加到Filter控件和Filter Editor控件支持的函数列表中。如果您在自定义函数类中包括了可选的Register和Unregister方法,则注册代码很短:

    //Program.cs file
    namespace DXSample {
    static class Program {
    [STAThread]
    static void Main() {
    IsWeekendFunction.Register();
    WithinDaysOfTodayFunction.Register();
    NotBeginsWithFunction.Register();

    // ...
    Application.Run(new Main());
    }
    }
    }

    从技术上讲,您的函数现在可用。如果您在Filter Editor控件的文本面板中手动编辑表达式,并使用这些自定义函数中的任何一个,则将生成有效的过滤条件。 但是到目前为止,这些函数将不会包含在可视化面板中。

    根据您的要求,使用以下三种技术之一将自定义函数添加到GUI。

    一种特定的控件

    若要使一个函数仅可用于一个特定的数据感知控件及其嵌入式Filter Editor控件,请为该控件的QueryCustomFunctions事件实现一个处理程序。使用以下代码,可以在嵌入式Filter Editor和Excel-style过滤器菜单中为数据网格使用IsWeekendFunction,而仅在过滤器编辑器中可见“ InsideDaysOfToday”函数。

    gridView1.QueryCustomFunctions += OnQueryCustomFunctions;

    private void OnQueryCustomFunctions(object sender,
    DevExpress.XtraGrid.Views.Grid.CustomFunctionEventArgs e) {
    if(e.PropertyType == typeof(DateTime)) {
    e.Add(IsWeekendFunction.FunctionName);
    if(e.IsFilterEditor)
    e.Add(WithinDaysOfTodayFunction.FunctionName);
    }
    }

    DevExpress Winforms使用技巧教程

    所有Filter和Filter Editor控件

    若要注册全局自定义函数来包含在所有Filter和Filter Editor控件中,请将它们添加到事件CriteriaOperator.QueryCustomFunctions的处理程序中。 此示例中全局注册了NotBeginsWith函数:

    static class Program {
    [STAThread]
    static void Main() {
    // ...
    CriteriaOperator.QueryCustomFunctions += OnQueryCustomUIFunctions;
    // ...
    }

    private static void OnQueryCustomUIFunctions(object sender,
    DevExpress.Data.Filtering.CustomFunctionEventArgs e) {
    if(e.PropertyType == typeof(string)) {
    e.Add(NotBeginsWithFunction.FunctionName);
    }
    }
    }

    特定于个别属性

    若要注册所有Filter和Filter Editor控件都应该可用但特定于数据类型属性的函数,请使用属性DevExpress.Data.Filtering.CustomFunction注释属性。 在此示例中,数据网格显示具有两个字符串属性Text和Info的类型,自定义函数NotBeginsWith仅适用于Info字段。

    [CustomFunction(NotBeginsWithFunction.FunctionName /*, Image = <image>*/)]
    public string Info {
    get { return info; }
    set {
    if (info != value) {
    info = value;
    OnPropertyChanged();
    }
    }
    }

    DevExpress Winforms使用技巧教程


    更多产品使用教程,尽在DevExpress中文网哦~

    DevExpress技术交流群:540330292      欢迎一起进群讨论

    扫描关注DevExpress中文网微信公众号,及时获取最新动态及最新资讯

    DevExpress中文网微信

  • 相关阅读:
    tomcat配置虚拟主机
    android widget 开发实例 : 桌面便签程序的实现具体解释和源代码 (上)
    Delphi 2007体验!
    ACE定时器
    Unity--关于优化方面的那些事儿(一)
    LTP介绍
    Java正則表達式入门
    Spring整合Hibernate的步骤
    ThreadPool.QueueUserWorkItem的性能问题
    用Bootstrap 写了个站点
  • 原文地址:https://www.cnblogs.com/AABBbaby/p/12564437.html
Copyright © 2011-2022 走看看