private void enregistrer_Click(object sender, EventArgs e) { if (motif.Text == "" || materiel.Text == "" || quantite.Text == "") { MessageBox.Show("Tous les champs sont obligatoires", "Champs invalides", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Double qtereelle = getQuantiteReelle(int.Parse(listeMateriaux.Rows[materiel.SelectedIndex][0].ToString())), qte; int artIndex = int.Parse(listeMateriaux.Rows[materiel.SelectedIndex][0].ToString()); artSuivi = lite.getMaterielTypeSuivi(artIndex); if (artSuivi == 2 && (typePiece == 1 || typePiece == 3)) { MessageBox.Show("Le type de mouvement choisi n'est pas autorise pour ce materiel", "Mouvement non autorise", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } qte = Double.Parse(quantite.Text.Replace(",", ".")); if (typePiece == 2 && qtereelle < qte && artSuivi == 1) { MessageBox.Show("l'etat du stock n'autorise pas la quantite saisie", "erreur sur la quantite saisie", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } String[] rows = new string[4]; String item = listeMateriaux.Rows[materiel.SelectedIndex][1].ToString(); rows[0] = listeMateriaux.Rows[materiel.SelectedIndex][0].ToString(); rows[1] = listeMateriaux.Rows[materiel.SelectedIndex][1].ToString(); rows[2] = quantite.Text.Replace(",", "."); rows[3] = motif.Text; materiauxDatagrid.Rows.Add(rows); motif.Text = ""; quantite.Text = ""; //materiel.SelectedIndex = -1; try { materiauxDatagrid.SelectedRows[0].Selected = false; } catch { } //MessageBox.Show(item, "Champs invalides", MessageBoxButtons.OK, MessageBoxIcon.Error); }