ошибка с приведением DataGridViewButtonCell к типу DataGridViewDisableButtonCell - PullRequest
0 голосов
/ 18 июня 2019

у меня ошибка Невозможно привести объект типа «System.Windows.Forms.DataGridViewButtonCell» к типу «Sento.DataGridViewDisableButtonCell». '

Моя цель состоит в том, чтобы при установке флажка ячейки кнопка включала

Мой код:

private void GrdSento_CellValueChanged(object sender, DataGridViewCellEventArgs e)
    {
        if(GrdSento.Columns[e.ColumnIndex].Name == "Check")
        {
            DataGridViewCheckBoxCell checkBoxCell = (DataGridViewCheckBoxCell)GrdSento.Rows[e.RowIndex].Cells["Check"];
            DataGridViewDisableButtonCell ButtonCell = (DataGridViewDisableButtonCell)GrdSento.Rows[e.RowIndex].Cells["Edit"];
            ButtonCell.Enabled = !(Boolean)checkBoxCell.Value;

            GrdSento.Invalidate();
        }
    }

Копирую по этой ссылке: DataGridViewDisableButtonCell

public class DataGridViewDisableButtonCell : DataGridViewButtonCell
{
    private bool enabledValue;
    public bool Enabled
    {
        get
        {
            return enabledValue;
        }
        set
        {
            enabledValue = value;
        }
    }
    // By default, enable the button cell.
    public DataGridViewDisableButtonCell()
    {
        this.enabledValue = true;
    }
}

DataGridViewDisableButtonCell уже унаследован от DataGridViewButtonCell, но все равно получает ошибку. Пожалуйста, помогите мне.

1 Ответ

0 голосов
/ 08 июля 2019

В вашем файле [Form] .Designer.cs измените

this.Edit = new System.Windows.Forms.DataGridViewButtonColumn();

до

this.Edit = new **DataGridViewDisableButtonColumn();**

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...