GridView 更改事件中的自定义单元格外观

Custom Cell Appearance in GridView change event

我正在使用以下代码禁用 XtraGrid GridView 中的复选框列(按预期工作)。从这个 post 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 事件中更改它,但我不知道如何引用行的 cell/column:

    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
        }

    }

您需要刷新“忽略”列中的单元格。您可以通过调用 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 事件以更新单元格外观。