Evaluar y enviar comentarios
MSDN
MSDN Library
 DataGridViewCellParsingEventHandler...
Contraer todo/Expandir todo Contraer todo
Esta página es específica de
Microsoft Visual Studio 2008/.NET Framework 3.5

Hay además otras versiones disponibles para:
Biblioteca de clases de .NET Framework
DataGridViewCellParsingEventHandler (Delegado)

Actualización: noviembre 2007

Representa el método que controlará un evento CellParsing de un control DataGridView.

Espacio de nombres:  System.Windows.Forms
Ensamblado:  System.Windows.Forms (en System.Windows.Forms.dll)
Visual Basic (Declaración)
Public Delegate Sub DataGridViewCellParsingEventHandler ( _
    sender As Object, _
    e As DataGridViewCellParsingEventArgs _
)
Visual Basic (Uso)
Dim instance As New DataGridViewCellParsingEventHandler(AddressOf HandlerMethod)
C#
public delegate void DataGridViewCellParsingEventHandler(
    Object sender,
    DataGridViewCellParsingEventArgs e
)
Visual C++
public delegate void DataGridViewCellParsingEventHandler(
    Object^ sender, 
    DataGridViewCellParsingEventArgs^ e
)
J#
/** @delegate */
public delegate void DataGridViewCellParsingEventHandler(
    Object sender,
    DataGridViewCellParsingEventArgs e
)
JScript
JScript no admite delegados.

Parámetros

sender
Tipo: System..::.Object
Origen del evento.
e
Tipo: System.Windows.Forms..::.DataGridViewCellParsingEventArgs
Una clase DataGridViewCellParsingEventArgs que contiene los datos del evento.

Controle el evento CellParsing para realizar una conversión personalizada de un valor especificado por el usuario a un valor del tipo especificado por la propiedad ValueType de la celda.

Al controlar el evento CellParsing, puede convertir el valor o personalizar la conversión predeterminada. Por ejemplo, puede convertir el valor mediante el método ParseFormattedValue de celda con los convertidores de tipos que elija. Como alternativa, puede dejar que los convertidores de tipos predeterminados analicen el valor, pero modifiquen las propiedades NullValue, DataSourceNullValue y FormatProvider del objeto devuelto por la propiedad DataGridViewCellParsingEventArgs..::.InheritedCellStyle, que se inicializa a través de la propiedad de celda InheritedStyle.

Al convertir el valor, debe reemplazar el valor con formato inicial de la propiedad ConvertEventArgs..::.Value por el valor convertido en el tipo especificado por la propiedad de celda ValueType. Para indicar que no es necesario seguir analizando, establezca la propiedad DataGridViewCellParsingEventArgs..::.ParsingApplied en true.

Cuando finaliza el controlador de eventos, si el valor de Value es nullNothingnullptrreferencia null (Nothing en Visual Basic) o no es del tipo correcto, o el valor de la propiedad ParsingApplied es false, se analiza Value con el método de celda ParseFormattedValue y los convertidores de tipos predeterminados. La implementación predeterminada de este método analiza el valor utilizando las propiedades NullValue, DataSourceNullValue y FormatProvider del estilo de celda pasado. Si el valor no es igual a NullValue, el valor se analiza utilizando la propiedad FormatProvider y los convertidores de tipo pasados.

Para personalizar la conversión de un valor de celda en un valor con formato para la presentación, controle el evento CellFormatting.

Para obtener más información sobre cómo controlar eventos, vea Utilizar eventos.

Cuando se crea un delegado de DataGridViewCellParsingEventHandler, se identifica el método que controlará el evento. Para asociar el evento a su controlador de eventos, agregue una instancia del delegado al evento. Siempre que se produce el evento, se llama a su controlador, a menos que se quite el delegado. Para obtener más información sobre los delegados de controladores de eventos, vea Eventos y delegados.

En el ejemplo de código siguiente se muestra cómo se utiliza DataGridViewCellParsingEventHandler para comprobar la validez de las entradas de fecha.

Visual Basic
' 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
C#
// 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;
                }
            }
        }
    }
}
Visual C++
// 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;
            }
         }
      }
   }
}

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

.NET Framework y .NET Compact Framework no admiten todas las versiones de cada plataforma. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.

.NET Framework

Compatible con: 3.5, 3.0, 2.0
Contenido de la comunidad   ¿Qué es Community Content?
Agregar contenido nuevo RSS  Anotaciones
Processing
© 2012 Microsoft. Reservados todos los derechos. Términos de uso | Marcas Registradas | Privacidad
Page view tracker