je veux charger DataGridView sans base de donné avec DataTable ,j'ai un problème dexécution ,mon exécution me donne juste un seule ligne et lorsque j'ajoute un nouvelle ligne ce déclenche l'erreur.
private void button1_Click(object sender, EventArgs e)
{
DataTable tab = new DataTable();
tab.Columns.Add("matricule", Type.GetType("System.Int32"));
tab.Columns.Add("nom", Type.GetType("System.String"));
tab.Columns.Add("part", Type.GetType("System.Int32"));
for (int i = 0; i <= dg.Rows.Count - 1; i++)
{
DataRow dr = tab.NewRow();
dr[0] = dg.Rows[i].Cells[0].Value;
dr[1] = dg.Rows[i].Cells[1].Value;
dr[2] = dg.Rows[i].Cells[2].Value;
tab.Rows.Add(dr);
}
DataRow mdr = tab.NewRow();
mdr[0] = t1.Text;
mdr[1] = t2.Text;
mdr[2] = t3.Text;
tab.Rows.Add(mdr);
dg.DataSource = tab;
}
merci d'avance
private void button1_Click(object sender, EventArgs e)
{
DataTable tab = new DataTable();
tab.Columns.Add("matricule", Type.GetType("System.Int32"));
tab.Columns.Add("nom", Type.GetType("System.String"));
tab.Columns.Add("part", Type.GetType("System.Int32"));
for (int i = 0; i <= dg.Rows.Count - 1; i++)
{
DataRow dr = tab.NewRow();
dr[0] = dg.Rows[i].Cells[0].Value;
dr[1] = dg.Rows[i].Cells[1].Value;
dr[2] = dg.Rows[i].Cells[2].Value;
tab.Rows.Add(dr);
}
DataRow mdr = tab.NewRow();
mdr[0] = t1.Text;
mdr[1] = t2.Text;
mdr[2] = t3.Text;
tab.Rows.Add(mdr);
dg.DataSource = tab;
}
merci d'avance