加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 如何从Cell_Leave事件中获取DataGridViewCell的值?

发布时间:2020-12-15 03:53:35 所属栏目:百科 来源:网络整理
导读: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; } }} 我正
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;
        }   
    }
}

我正在尝试获取事件触发的单元格的值.

当我尝试将发送者强制转换为DataGridViewCell时会触发异常:

Unable to cast object of type
‘System.Windows.Forms.DataGridView’ to
type
‘System.Windows.Forms.DataGridViewCell’.

你推荐我做什么?

我需要检查值是否小于20,如果是,则将其提高到21.

解决方法

尝试使用DataGrid [e.RowIndex,e.ColumnIndex] .Value.我希望发送者更可能是DataGridView对象而不是单元本身.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读