读书人

求教关于Datagridview 的 CellValueCh

发布时间: 2012-04-24 14:15:38 作者: rapoo

求教关于Datagridview 的 CellValueChanged 事件问题
想实现 手动输入第3列与第5列的数值,第六列自动求出两列数值的乘积,代码如下,运行提示未处理的“System.StackOverflowException”类型的异常,求教原因和改正方法.....

private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{

int i = e.RowIndex;
if (i >= 0)
{
dataGridView1.Rows[e.RowIndex].Cells[6].Value = Math.Round((Convert.ToDecimal(dataGridView1.Rows[e.RowIndex].Cells[3].Value) * Convert.ToDecimal(dataGridView1.Rows[e.RowIndex].Cells[5].Value)));
}
}


[解决办法]
Cells[6].Value,这是第7列,下标从0开始
[解决办法]
你试试这段代码...不知道你哪里觉得错了?

C# code
int i = e.RowIndex;            try            {                if (i >= 0)                {                    dataGridView1.Rows[e.RowIndex].Cells[7].Value                        = Math.Round((Convert.ToDecimal(dataGridView1.Rows[e.RowIndex].Cells[4].Value) *                        Convert.ToDecimal(dataGridView1.Rows[e.RowIndex].Cells[5].Value)));                }            }            catch (Exception ex)            {                throw new Exception(ex.Message);            } 

读书人网 >C#

热点推荐