本帖最后由 tyco2007 于 2010-01-30 17:04:06 编辑

解决方案 »

  1.   

      private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
            {
                if (e.ColumnIndex ==2 || e.ColumnIndex == 3)
                {
                    int value1 = dataGridView1[2, e.RowIndex].Value == null ? 0 : Int32.Parse(dataGridView1[2, e.RowIndex].Value.ToString());
                    int value2 = dataGridView1[3, e.RowIndex].Value == null ? 0 : Int32.Parse(dataGridView1[3, e.RowIndex].Value.ToString());
                    dataGridView1[4, e.RowIndex].Value = value1 + value2;
                }
            }
    楼主运算的时间不应是焦点在第4列时,而应是在第2列或第3列任一列编辑完后就要计算 那用户要是不点第4列呢,岂不是就不计算了
      

  2.   

    First you should define this event!
      

  3.   

    提示是你要先定义这个事件,你的datagridview是从工具箱中拉出来的还是new()方法产生的?
    如果是从工具箱中拉出来的,直接在事件CellEndEdit双击产生代码行填写代码即可
    如果是new产生的可以为之定义一个事件如:
    datagridView1.CellEndEdit+=new DataGridViewCellEventHandler(dataGridView1_CellEndEdit);