DataGridViewCellParsingEventArgs.ColumnIndex Propriété
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Obtient l'index de colonne des données de cellule qui requièrent l'analyse.
public:
property int ColumnIndex { int get(); };
public int ColumnIndex { get; }
member this.ColumnIndex : int
Public ReadOnly Property ColumnIndex As Integer
Valeur de propriété
Index de colonne de la cellule qui a été modifiée.
Exemples
L’exemple de code suivant montre comment utiliser ColumnIndex pour découvrir si la cellule modifiée se trouve dans la colonne de date.
// 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
Remarques
Utilisez la ColumnIndex propriété pour obtenir un index dans la Columns propriété d’un DataGridView.