DataGridView contains DataGridViewRows collection. Each row in the collection is
DataGridViewRow[
^].
To get the total sum of selected rows, you need to iterate through the collection of rows:
private void button1_Click(object sender, EventArgs e)
{
DataGridViewCell dc = null;
DataGridViewCheckBoxCell cbx = null;
double mySum = 0;
string s = string.Empty;
foreach (DataGridViewRow dr in dataGridView1.Rows)
{
dc = dr.Cells[2];
cbx = (DataGridViewCheckBoxCell)dc;
if (Convert.ToBoolean(cbx.Value))
{
mySum += double.Parse(dr.Cells[0].Value.ToString());
}
}
s = String.Format("Total sum: {0}", mySum.ToString());
MessageBox.Show(s);
}
}