Bonjour,

Voila je sais comment ajouter plusieurs lignes dans un datagrid view. Voila mon probleme:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
DataGridViewRow oDataGridViewRow = new DataGridViewRow();
DataTable dt = new DataTable();
            cmd = new SqlCommand("GetOrganizations", cnx); //procedure stocké
            cmd.CommandType = CommandType.StoredProcedure;
            dta = new SqlDataAdapter(cmd);
            dta.Fill(dt);
 
 
 
            for (i = 0; i < dt.Rows.Count; i++)
            {
 
                id.CellTemplate.Value = dt.Rows[i][0];
                nom.CellTemplate.Value = dt.Rows[i][1];
                email.CellTemplate.Value = dt.Rows[i][2];
                tel.CellTemplate.Value = dt.Rows[i][3];
                statut.Value = dt.Rows[i][4];
 
                oDataGridViewRow.Cells.Add(id.CellTemplate); // <== erreur
                oDataGridViewRow.Cells.Add(nom.CellTemplate);
                oDataGridViewRow.Cells.Add(email.CellTemplate);
                oDataGridViewRow.Cells.Add(tel.CellTemplate);
                oDataGridViewRow.Cells.Add(statut);
 
                dataGridView1.Rows.Add(oDataGridViewRow);
            }
l'erreur retourné c'est :
Cette collection appartient déjà à un contrôle DataGridView. Cette opération n'est plus valide.
P.S. L'erreur se declenche si j'ai plus d'une ligne dans ma datatable sinon ça marche trés bien