【发布时间】:2011-06-15 05:33:36
【问题描述】:
我有一个 GridView,其中包含 Code、Experience、Salary、Bonus
列Code、Experience 和 Salary 列的数据来自 BindingSource,我需要计算 Bonus 的数据strong> 基于经验和薪水。
所以我为DataGridView 创建了RowsAdded 事件并添加了以下代码
int index = employeeBindingSource.Position;
Employee emp = (Employee)employeeBindingSource.Current;
double bonus = (emp.Experience < 4 ? 0.08f : 0.12f) * emp.Salary * 12;
employeeDataGridView.Rows[index].Cells[3].Value = bonus.ToString("0.00"); //setting value for bonus column
employeeBindingSource.MoveNext();
但我只得到两行的 Bouns。
所以我在这个事件中注释了代码并创建了另一个事件RowStateChanged添加了上面的代码,它工作正常。
RowsAdded 事件有什么问题? RowStateChanged 是计算奖金列的正确事件吗?
谢谢。
【问题讨论】:
标签: c# winforms gridview .net-4.0 bindingsource