【问题标题】:Add custom control to DevExpress GridControl将自定义控件添加到 DevExpress GridControl
【发布时间】:2018-01-04 21:16:30
【问题描述】:

我有一个为波斯日历准备的自定义 DateTimePicker 控件。有没有办法将它添加到 DevExpress GridControl 列? 请帮帮我。

【问题讨论】:

    标签: devexpress gridcontrol


    【解决方案1】:

    发件人:Creating a custom (RepositoryItem) ImageComboBox

    如果您希望在 GridControl 中使用您的自定义控件,则必须 创建编辑器及其 RepositoryItem 后代。

    完整信息请参阅Custom EditorsHow to register a custom editor for use in the XtraGrid 文章 关于如何创建自定义控件。你可以找到一些自定义编辑器 我们示例中的后代:editor descendants

    RepositoryItem 类包含编辑器设置并用作 网格中单元格的模板。在显示模式下,GridControl 仅通过 RepositoryItem 的方法绘制单元格内容。在编辑 模式下,GridControl 通过 RepositoryItem.CreateEditor 方法。因此,如果您希望将项目添加到 网格初始化时使用的编辑器,在 RepositoryItem 级别。

    如果您使用以下代码处理GridView.CustomRowCellEdit 事件,您可以为自动过滤行设置编辑器

        RepositoryItemDateEdit rd = new RepositoryItemDateEdit();
        void gridView1_CustomRowCellEdit(object sender, DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs e) {
          GridView view = sender as GridView;
          if(e.Column.FieldName == "DOB" && view.IsFilterRow(e.RowHandle)) {
              e.RepositoryItem = rd;
          }
        }
    

    查看Assigning Editors to Columns and Card Fields 帮助文章,了解如何将特定编辑器分配给特定 GridView 的列。

    我希望这些信息对您有用。

    【讨论】:

    • 非常感谢。我可以通过电子邮件与您联系吗?
    • @R.Salehi:你可以把你的问题放在这里或DevExpress forum。在您遇到问题的地方提供有问题的代码,以便每个人都能理解问题并回复您以获得正确的解决方案。如果它确实有效,那么您可以寻求帮助here
    • 此外,RepositoryItemAnyControl class 可用于在 GridControl、TreeList 等中放置任何自定义编辑器...
    猜你喜欢
    • 2014-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多