Hi guys,
I've got a windows form with a datagridview linked to an access database. The third column in the datagridview is a list of numeric values. On load up I would like a textbox to display the average of all the values in this column. Can't quite figure it out.
Here's the code I have written:
int Counter = 0;
double AverageCalc = 0;
while (Counter < dtaJanuray.Rows.Count)
{
string Average = null;
Average = datagridview.SelectedRows[Counter].Cells[2].Value.ToString();
AverageCalc = AverageCalc + Convert.ToDouble(Average);
Counter++;
}
AverageCalc = AverageCalc / datagridview.Rows.Count;
txtAverage.Text = AverageCalc.ToString();
It loops through once, and then fails at:
Average = datagridview.SelectedRows[Counter].Cells[2].Value.ToString();
When Counter = 1
I'm not really sure what else to try, any advise would be greatly appreciated.
Thanks
Martin