我试图获取数据,一旦用户键进入数据网格视图,它将自动添加data1和数据2并显示总数但它不起作用这里是我的代码到目前为止我设法让他们添加使用添加按钮
private void dataGridView1_CellStyleContentChanged(object sender, DataGridViewCellStyleContentChangedEventArgs e)
{
try
{
var a = Convert.ToDouble(dataGridView1.Rows[1].Cells[0].Value) + Convert.ToDouble(dataGridView1.Rows[2].Cells[0].Value);
dataGridView1.Rows[3].Cells[0].Value = a;
var b = Convert.ToDouble(dataGridView1.Rows[1].Cells[1].Value) + Convert.ToDouble(dataGridView1.Rows[2].Cells[1].Value);
dataGridView1.Rows[3].Cells[1].Value = b;
var c = Convert.ToDouble(dataGridView1.Rows[1].Cells[2].Value) + Convert.ToDouble(dataGridView1.Rows[2].Cells[2].Value);
dataGridView1.Rows[3].Cells[2].Value = c;
var d = Convert.ToDouble(dataGridView1.Rows[1].Cells[3].Value) + Convert.ToDouble(dataGridView1.Rows[2].Cells[3].Value);
dataGridView1.Rows[3].Cells[3].Value = d;
var f = Convert.ToDouble(dataGridView1.Rows[1].Cells[4].Value) + Convert.ToDouble(dataGridView1.Rows[2].Cells[4].Value);
dataGridView1.Rows[3].Cells[4].Value = f;
var g = Convert.ToDouble(dataGridView1.Rows[1].Cells[5].Value) + Convert.ToDouble(dataGridView1.Rows[2].Cells[5].Value);
dataGridView1.Rows[3].Cells[5].Value = g;
var h = Convert.ToDouble(dataGridView1.Rows[1].Cells[6].Value) + Convert.ToDouble(dataGridView1.Rows[2].Cells[6].Value);
dataGridView1.Rows[3].Cells[6].Value = h;
var i = Convert.ToDouble(dataGridView1.Rows[1].Cells[7].Value) + Convert.ToDouble(dataGridView1.Rows[2].Cells[7].Value);
dataGridView1.Rows[3].Cells[7].Value = i;
var j = Convert.ToDouble(dataGridView1.Rows[1].Cells[8].Value) + Convert.ToDouble(dataGridView1.Rows[2].Cells[8].Value);
dataGridView1.Rows[3].Cells[8].Value = j;
var k = Convert.ToDouble(dataGridView1.Rows[1].Cells[9].Value) + Convert.ToDouble(dataGridView1.Rows[2].Cells[9].Value);
dataGridView1.Rows[3].Cells[9].Value = k;
var l = Convert.ToDouble(dataGridView1.Rows[1].Cells[10].Value) + Convert.ToDouble(dataGridView1.Rows[2].Cells[10].Value);
dataGridView1.Rows[3].Cells[10].Value = l;
var n = Convert.ToDouble(dataGridView1.Rows[1].Cells[11].Value) + Convert.ToDouble(dataGridView1.Rows[2].Cells[11].Value);
dataGridView1.Rows[3].Cells[11].Value = n;
}
catch
{
MessageBox.Show("Never run");
}
}