CellValueChanged 这个事件的 e参数是有当前触发事件的行列index的
e.ColumnIndex
e.RowIndex
我试了下 下面的可以
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
List list = new List();
list.Add(new l() {a=1,b=2,c=3});
dataGridView1.AutoGenerateColumns = true;
dataGridView1.DataSource = list;
}
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
int a = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[0].Value);
int b = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[1].Value);
dataGridView1.Rows[e.RowIndex].Cells[2].Value = a + b;
}
}
public class l
{
public int a{get;set;}
public int b { get; set; }
public int c { get; set; }
}