DataGridViewCellParsingEventArgs Classe

Definição

Fornece dados para o CellParsing evento de um DataGridView controlo.

public ref class DataGridViewCellParsingEventArgs : System::Windows::Forms::ConvertEventArgs
public class DataGridViewCellParsingEventArgs : System.Windows.Forms.ConvertEventArgs
type DataGridViewCellParsingEventArgs = class
    inherit ConvertEventArgs
Public Class DataGridViewCellParsingEventArgs
Inherits ConvertEventArgs
Herança
DataGridViewCellParsingEventArgs

Exemplos

O exemplo de código seguinte demonstra a utilização DataGridViewCellParsingEventArgs para verificar a validade das entradas de data.

// Handling CellParsing allows one to accept user input, then map it to a different
// internal representation.
void dataGridView1_CellParsing( Object^ /*sender*/, DataGridViewCellParsingEventArgs^ e )
{
   if ( this->dataGridView1->Columns[ e->ColumnIndex ]->Name->Equals( "Release Date" ) )
   {
      if ( e != nullptr )
      {
         if ( e->Value != nullptr )
         {
            try
            {
               // Map what the user typed into UTC.
               e->Value = DateTime::Parse( e->Value->ToString() ).ToUniversalTime();

               // Set the ParsingApplied property to 
               // Show the event is handled.
               e->ParsingApplied = true;
            }
            catch ( FormatException^ /*ex*/ ) 
            {
               // Set to false in case another CellParsing handler
               // wants to try to parse this DataGridViewCellParsingEventArgs instance.
               e->ParsingApplied = false;
            }
         }
      }
   }
}
// Handling CellParsing allows one to accept user input, then map it to a different
// internal representation.
private void dataGridView1_CellParsing(object sender, DataGridViewCellParsingEventArgs e)
{
    if (this.dataGridView1.Columns[e.ColumnIndex].Name == "Release Date")
    {
        if (e != null)
        {
            if (e.Value != null)
            {
                try
                {
                    // Map what the user typed into UTC.
                    e.Value = DateTime.Parse(e.Value.ToString()).ToUniversalTime();
                    // Set the ParsingApplied property to 
                    // Show the event is handled.
                    e.ParsingApplied = true;
                }
                catch (FormatException)
                {
                    // Set to false in case another CellParsing handler
                    // wants to try to parse this DataGridViewCellParsingEventArgs instance.
                    e.ParsingApplied = false;
                }
            }
        }
    }
}
' Handling CellParsing allows one to accept user input, then map it to a different
' internal representation.
Private Sub dataGridView1_CellParsing(ByVal sender As Object, _
    ByVal e As DataGridViewCellParsingEventArgs) _
    Handles dataGridView1.CellParsing

    If Me.dataGridView1.Columns(e.ColumnIndex).Name = _
        "Release Date" Then
        If e IsNot Nothing Then
            If e.Value IsNot Nothing Then
                Try
                    ' Map what the user typed into UTC.
                    e.Value = _
                    DateTime.Parse(e.Value.ToString()).ToUniversalTime()
                    ' Set the ParsingApplied property to 
                    ' Show the event is handled.
                    e.ParsingApplied = True

                Catch ex As FormatException
                    ' Set to false in case another CellParsing handler
                    ' wants to try to parse this DataGridViewCellParsingEventArgs instance.
                    e.ParsingApplied = False
                End Try
            End If
        End If
    End If
End Sub

Observações

Gerir o CellParsing evento para fornecer uma conversão personalizada de valor de um valor especificado pelo utilizador para um valor do tipo especificado pela propriedade da célula ValueType .

Quando gerir o CellParsing evento, pode converter o valor você próprio ou pode personalizar a conversão padrão. Por exemplo, pode converter o valor por si mesmo usando o método da célula ParseFormattedValue com conversores de tipos à sua escolha. Alternativamente, pode deixar os conversores de tipos padrão analisarem o valor, mas modificar o NullValue, , e FormatProvider as propriedades do objeto devolvido pela DataGridViewCellParsingEventArgs.InheritedCellStyle propriedade, que é inicializada usando a propriedade da célula InheritedStyleDataSourceNullValue.

Quando converter o valor por si próprio, substitua o valor inicial formatado da ConvertEventArgs.Value propriedade pelo valor convertido no tipo especificado pela propriedade da célula ValueType . Para indicar que não é necessária mais análise sintática, defina a DataGridViewCellParsingEventArgs.ParsingApplied propriedade para true.

Quando o gestor de eventos termina, se o Value for ou não do tipo correto, ou a ParsingApplied propriedade for false, o Value é analisado usando o método da célula ParseFormattedValue com conversores de tipos por defeitonull. A implementação padrão deste método analisa o valor usando , NullValueDataSourceNullValue, e FormatProvider propriedades do estilo de célula passado. Se o valor não for igual a NullValue, o valor é analisado usando a FormatProvider propriedade e os conversores de tipos são passados.

Para personalizar a conversão de um valor de célula num valor formatado para exibição, trate do CellFormatting evento.

Para mais informações sobre como gerir eventos, consulte Gestão e Levantamento de Eventos.

Construtores

Name Description
DataGridViewCellParsingEventArgs(Int32, Int32, Object, Type, DataGridViewCellStyle)

Inicializa uma nova instância da DataGridViewCellParsingEventArgs classe.

Propriedades

Name Description
ColumnIndex

Obtém o índice da coluna dos dados da célula que requer análise.

DesiredType

Obtém o tipo de dado do valor desejado.

(Herdado de ConvertEventArgs)
InheritedCellStyle

Obtém ou define o estilo aplicado à célula editada.

ParsingApplied

Obtém ou define um valor que indica se o valor de uma célula foi analisado com sucesso.

RowIndex

Obtém o índice de linha da célula que requer análise sintática.

Value

Obtém ou define o valor do ConvertEventArgs.

(Herdado de ConvertEventArgs)

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)

Aplica-se a

Ver também