Evenement DataError et Datagridview
Bonjour,
J'aimerai qu'à chaque modification, ou insertion dans mon datagridview, il y ait vérification si une erreur existe, dans lequel cas, des messages d'erreurs se montrent.
J'ai donc créé la fonction datagrid1_dataerror suivant:
Code:
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 27 28
| private void datagrid1_DataError(object sender, DataGridViewDataErrorEventArgs anError)
{
if (anError.Exception != null && anError.Context == DataGridViewDataErrorContexts.Commit)
{
MessageBox.Show("La clé de dossier doit être unique.");
}
if (anError.Context == DataGridViewDataErrorContexts.CurrentCellChange)
{
MessageBox.Show("Cell change");
}
if (anError.Context == DataGridViewDataErrorContexts.Parsing)
{
MessageBox.Show("parsing error");
}
if (anError.Context == DataGridViewDataErrorContexts.LeaveControl)
{
MessageBox.Show("leave control error");
}
if ((anError.Exception) is ConstraintException)
{
MessageBox.Show("Une erreur de contrainte d'unicité s'est produite. Merci de vérifier que la référence d'étude que vous avez saisi n'est pas déjà existente.");
DataGridView view = (DataGridView)sender;
view.Rows[anError.RowIndex].ErrorText = "an error";
view.Rows[anError.RowIndex].Cells[anError.ColumnIndex].ErrorText = "an error";
anError.ThrowException = false;
}
} |
Mais il fonctionne pas. Si quelqu'un peut m'éclairer la dessus.
Merci