我有错误 无法将类型为“ 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继承,但是仍然会出错。请帮助我。
答案 0 :(得分:0)
在[Form] .Designer.cs文件中,更改
this.Edit = new System.Windows.Forms.DataGridViewButtonColumn();
到
this.Edit = new **DataGridViewDisableButtonColumn();**