1
Go to your event DataGridView
and choose the option CellEndEdit
.
Within this event method enter the following code:
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
string v = this.dataGridView1[e.ColumnIndex, e.RowIndex].Value?.ToString().Trim();
foreach (DataGridViewRow row in this.dataGridView1.Rows)
{
if (row.Index >= this.dataGridView1.Rows.Count - 1) break;
if (row.Cells[3].Value?.ToString().Trim() == v && row.Index != e.RowIndex)
{
MessageBox.Show("Opa, já existe um ramal igual a esse");
this.dataGridView1[e.ColumnIndex, e.RowIndex].Value = null;
break;
}
}
}
Cells[3]
is the column where the branches are located.
When someone type an extension that already exists in the column, the message will appear.
ok. But what would be an interesting method to be able to do this check? I can’t find anywhere ;'(
– Paulo Antunes de Souza
It would be more useful if you include yourself an example in your reply.
– Bruno Warmling