Quote:
i want to get sum of selected row of marks column
If i understand you correctly, you want to get collection of
DataGridView.SelectedRows[
^] then to display
sum(marks)
in label.
So, you should use
DataGridView.SelectionChanged Event (System.Windows.Forms)[
^] to be able to achieve that. Use below code inside that event (body of event):
int sum = 0;
foreach(DataGridViewRow dgr in dataGridView1.SelectedRows)
{
sum+= dgr[6].Value;
}
label1.Text = sum.ToString();
Another way is to use
Linq[
^]:
label1.Text = dataGridView1.SelectedRows.Cast<DataGridViewRow>().Sum(dgr=>dgr.Cells[6].Value).ToString();