DataGridViewCellValidatingEventArgs Classe
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Fornece dados para o CellValidating evento de um DataGridView controlo.
public ref class DataGridViewCellValidatingEventArgs : System::ComponentModel::CancelEventArgs
public class DataGridViewCellValidatingEventArgs : System.ComponentModel.CancelEventArgs
type DataGridViewCellValidatingEventArgs = class
inherit CancelEventArgs
Public Class DataGridViewCellValidatingEventArgs
Inherits CancelEventArgs
- Herança
Exemplos
O exemplo de código seguinte trata do CellValidating evento para garantir que apenas inteiros positivos sejam introduzidos pelo utilizador. Este exemplo faz parte de um exemplo maior disponível no VirtualMode tópico de referência.
void VirtualConnector::dataGridView1_CellValidating
(Object^ sender, DataGridViewCellValidatingEventArgs^ e)
{
int newInteger;
// Don't try to validate the 'new row' until finished
// editing since there
// is not any point in validating its initial value.
if (dataGridView1->Rows[e->RowIndex]->IsNewRow)
{
return;
}
if (!Int32::TryParse(e->FormattedValue->ToString(),
newInteger) || (newInteger < 0))
{
e->Cancel = true;
}
}
private void dataGridView1_CellValidating(object sender,
DataGridViewCellValidatingEventArgs e)
{
dataGridView1.Rows[e.RowIndex].ErrorText = "";
int newInteger;
// Don't try to validate the 'new row' until finished
// editing since there
// is not any point in validating its initial value.
if (dataGridView1.Rows[e.RowIndex].IsNewRow) { return; }
if (!int.TryParse(e.FormattedValue.ToString(),
out newInteger) || newInteger < 0)
{
e.Cancel = true;
dataGridView1.Rows[e.RowIndex].ErrorText = "the value must be a non-negative integer";
}
}
Private Sub dataGridView1_CellValidating(ByVal sender As Object, _
ByVal e _
As DataGridViewCellValidatingEventArgs) _
Handles dataGridView1.CellValidating
Me.dataGridView1.Rows(e.RowIndex).ErrorText = ""
Dim newInteger As Integer
' Don't try to validate the 'new row' until finished
' editing since there
' is not any point in validating its initial value.
If dataGridView1.Rows(e.RowIndex).IsNewRow Then Return
If Not Integer.TryParse(e.FormattedValue.ToString(), newInteger) _
OrElse newInteger < 0 Then
e.Cancel = True
Me.dataGridView1.Rows(e.RowIndex).ErrorText = "the value must be a non-negative integer"
End If
End Sub
Observações
O DataGridView.CellValidating evento permite-lhe cancelar alterações na célula atual quando o novo valor não é válido. Use a FormattedValue propriedade para determinar o valor atual. Para determinar o estado da célula atual, use as RowIndex propriedades e ColumnIndex para aceder à célula através da DataGridView.Rows coleção. Para cancelar a alteração, defina a Cancel propriedade para true.
Quando este evento é cancelado em modo data-bound, o novo valor não é enviado para a fonte de dados subjacente. Quando este evento é cancelado em modo virtual, o DataGridView.CellValuePushed evento não será elevado.
Propriedades
| Name | Description |
|---|---|
| Cancel |
Recebe ou define um valor que indica se o evento deve ser cancelado. (Herdado de CancelEventArgs) |
| ColumnIndex |
Obtém o índice da coluna da célula que precisa de ser validada. |
| FormattedValue |
Obtém o conteúdo formatado da célula que precisa de ser validada. |
| RowIndex |
Obtém o índice da linha da célula que precisa de ser validada. |
Métodos
| Name | Description |
|---|---|
| Equals(Object) |
Determina se o objeto especificado é igual ao objeto atual. (Herdado de Object) |
| GetHashCode() |
Serve como função de hash predefinida. (Herdado de Object) |
| GetType() |
Obtém o Type da instância atual. (Herdado de Object) |
| MemberwiseClone() |
Cria uma cópia superficial do atual Object. (Herdado de Object) |
| ToString() |
Devolve uma cadeia que representa o objeto atual. (Herdado de Object) |