c# - 无法在 datagridview 中的单元格离开事件中获取当前单元格值

标签 c# datagridview

当我在离开当前单元格时试图获取该单元格的值时,我无法获取该单元格的值。我的代码在 Cell_Leave 事件中

    if (e.ColumnIndex == 5)
        {
            double netVal;
            double.TryParse(dgvRegister.Rows[e.RowIndex].Cells[4].Value.ToString(), out netVal);

            double Vat;
            double.TryParse(dgvRegister.Rows[e.RowIndex].Cells[5].Value.ToString(), out Vat);

            string amt = ((netVal / 100) * Vat).ToString();
        }

在这种情况下,我得到的是 cells[4] 值,当我得到 cells[5].value 时,我得到的是 null value。为什么我得到一个空值?请帮我找到解决方案。

最佳答案

尝试将 Value 更改为 EditedFormattedValue

dgvRegister.Rows[e.RowIndex].Cells[4].EditedFormattedValue.ToString()

关于c# - 无法在 datagridview 中的单元格离开事件中获取当前单元格值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13909188/

相关文章:

c# - 一次更改多个控件属性

c# - 使用反射 C# 将动态对象转换为类型

c# - 如何使用 Localizer 本地化 asp-action

.net datagridview 单元格最小宽度

DataGridViewCellStyle 显示以千为单位的数值数据

c# - 为什么有些闭包比其他的闭包 'Friendlier'?

c# - 通过 IntPtr 循环?

c# - 如何在 C# 中单击按钮时将 datagridview 值插入数据库

c# - 如何在C#中使用Datagridview显示XML数据

.net - DataGridView 中的列数