1
Answer

ERROR: Specified cast is not valid.

praveen kumar

praveen kumar

9y
1.1k
1
Hi,
 
 In datagridview, i am calculating(SUM) the timespan of the whole column, for the i am using the following code but it showing error "Specified cast is not valid.". kindly help me to sort out this issue
 
TimeSpan sum = TimeSpan.Zero;
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
sum += (TimeSpan)dataGridView1.Rows[i].Cells[4].Value;

}
label2.Text = sum.ToString(); 
Answers (1)