【问题标题】:Help on C# DevExpress XtraGrid GridControl - making checkbox in cell invisible帮助 C# DevExpress XtraGrid GridControl - 使单元格中的复选框不可见
【发布时间】:2011-01-25 23:33:41
【问题描述】:

我有一个 GridControl 视图,该视图正在填充一列作为布尔值,以将值显示为复选框。

但是,我希望根据其他列的状态隐藏一些复选框。我尝试使用gridView_CustomDrawCell() 事件,但找不到合适的属性。

我希望找到一个 visible 属性设置为 false,但似乎没有。

也许可以在填充视图时隐藏复选框,但我想不出一个。

有谁知道这是否可行,如何实现?

非常感谢!

【问题讨论】:

    标签: c# gridview checkbox devexpress


    【解决方案1】:

    您可以尝试清除 Graphics 并将事件标记为已处理:

    private void gridView_CustomDrawCell(object sender, RowCellCustomDrawEventArgs e)
    {
        if (ConditionIsMet())
        {
            e.Graphics.Clear(e.Appearance.BackColor);
            e.Handled = true;
        }
    }
    

    如果它不起作用,这是另一个想法:处理 CustomRowCellEditCustomRowCellEditForEditing 事件,并删除编辑器:

    private void gridView_CustomRowCellEdit(object sender, CustomRowCellEditEventArgs e)
    {
        if (ConditionIsMet())
        {
            e.RepositoryItem = null;
        }
    }
    

    【讨论】:

    • 哇,我使用这个产品已经 3 年多了,从来没有意识到你可以将 RepositoryItem 设置为 null,我一直只是为禁用的编辑器创建了一个默认项目。这将节省我一些时间!
    • @Aaronaught,我不知道这是否真的有效,这只是一个建议;)
    • 我已尝试将存储库项设置为 null,但它不起作用。它使用默认编辑器,可能基于相应的属性类型。
    • 感谢 Thomas,e.handled=true 方法奏效了。感谢大家的帮助。
    【解决方案2】:

    我在一个项目中为此所做的是将 RadioGroup 设置为没有项目的控件,因此它显示为空白。

    private void viewTodoList_CustomRowCellEdit(object sender, DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs e)
            {
                if (e.Column == CheckMarkColumn)
                {
                    if (ConditionIsMet())
                    {
                        e.RepositoryItem = new DevExpress.XtraEditors.Repository.RepositoryItemRadioGroup();
                    }
                }
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-07
      • 1970-01-01
      • 1970-01-01
      • 2018-03-24
      • 1970-01-01
      • 1970-01-01
      • 2013-07-22
      • 1970-01-01
      相关资源
      最近更新 更多