首先设置dataGridView控件的属性SelectionMode为FullColumnSelect(选中整列)
点击计算按钮的代码
private void button1_Click(object sender, EventArgs e)
{
Listld = new List ();
foreach (DataGridViewTextBoxCell item in dataGridView1.SelectedCells)
{
ld.Add(Convert.ToDouble(item.Value));
}
var avg= ld.Average(a => a);
MessageBox.Show("平均值是:"+avg);
}