【问题标题】:Custom Cell Appearance in GridView change eventGridView 更改事件中的自定义单元格外观
【发布时间】:2016-03-02 11:44:02
【问题描述】:

我正在使用以下代码禁用 XtraGrid GridView 中的复选框列(按预期工作)。从这篇帖子https://www.devexpress.com/Support/Center/Question/Details/Q423605得到代码:

    private void GridViewWeeklyPlan_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
    {
        if (e.Column.FieldName == "Ignore")
        {
            CheckEditViewInfo viewInfo = ((GridCellInfo)e.Cell).ViewInfo as CheckEditViewInfo;
            viewInfo.CheckInfo.State = DevExpress.Utils.Drawing.ObjectState.Disabled;
        }
    }

问题

我想在某个列更改并具有值时再次启用该复选框。这是我卡住的地方,我认为我可以在 GridView 的 CellValueChanged 事件中更改它,但我不知道如何引用该行的单元格/列:

    private void GridViewWeeklyPlan_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
    {
        if (e.Column.FieldName != "Reason") return;


        if (String.IsNullOrEmpty(e.Value.ToString()))
        {
            //Make sure the checkbox is disabled again
        }
        else
        {
            //Enable the checkbox to allow user to select it
        }

    }

【问题讨论】:

    标签: devexpress devexpress-windows-ui


    【解决方案1】:

    您需要刷新忽略列中的一个单元格。您可以通过调用GridView.RefreshRowCell 方法来做到这一点。为了识别需要刷新的行,CellValueChanged 事件提供了 e.RowHandle 参数。

    private void GridViewWeeklyPlan_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            if (e.Column.FieldName != "Reason") return;
            GridView view = (GridView)sender;   
            view.RefreshRowCell(e.RowHandle, view.Columns["Ignore"]);
    
        }
    

    CustomDrawCell 事件将再次引发以更新单元格外观。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-07
      • 1970-01-01
      • 1970-01-01
      • 2023-04-02
      • 2019-03-02
      相关资源
      最近更新 更多