I have in my project a GridView where I manually enter data in the last column (index 7) and a PieChart that should be updated according to this last column, however, however much I can get the data from column I can not pass them to the Chart. Here is the code where I captured the values:
TimeSpan[] permanencia = new TimeSpan[dataGridView1.Rows.Count];
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
permanencia[i] = TimeSpan.Parse(Convert.ToString(dataGridView1.Rows[i].Cells[7].Value));
}
So far so good, but when I try to pass the data to update my Chart, nothing happens. Here is the code:
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
ds = new DataSet(Convert.ToString(permanencia[i]));
chart1.DataSource = ds;
chart1.DataBind();
chart1.Update();
}
Could anyone help me? I'm a beginner with Charts ...
Note: I am working with WindowsForm and as already mentioned, the data in this column is generated manually ...
On request, it follows the completion code of the last column, UNICA filled in this way ...
// CALCULO DA PERMANÊNCIA E INSERÇÃO DA COLUNA COM OS RESPECTIVOS DADOS
DateTime ent = new DateTime();
DateTime sad = new DateTime();
TimeSpan permanencia = new TimeSpan();
DataGridViewRow l = dataGridView1.Rows[0];
DataGridViewCell c = l.Cells[0];
dataGridView1.Columns.Add("colunaPermanencia", "Permanencia");
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
ent = Convert.ToDateTime(dataGridView1.Rows[i].Cells[4].Value);
sad = Convert.ToDateTime(dataGridView1.Rows[i].Cells[6].Value);
permanencia = sad - ent;
dataGridView1.Rows[i].Cells["colunaPermanencia"].Value = permanencia.ToString();
}