Onl*_*ere 6 c# int datagridview winforms
private void dataGridView1_CellLeave(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex > 1)
{
int cellValue = Convert.ToInt32(((DataGridViewCell)sender).Value);
if (cellValue < 20)
{
((DataGridViewCell)sender).Value = 21;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试获取事件触发的单元格的值.
当我尝试强制sender转换为DataGridViewCell:
无法将类型为"System.Windows.Forms.DataGridView"的对象强制转换为"System.Windows.Forms.DataGridViewCell".
你推荐我做什么?
我需要检查值是否小于20,如果是,则将其提高到21.