DataGridViewCellParsingEventArgs.ColumnIndex Proprietà
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Ottiene l'indice di colonna dei dati delle celle che richiedono l'analisi.
public:
property int ColumnIndex { int get(); };
public int ColumnIndex { get; }
member this.ColumnIndex : int
Public ReadOnly Property ColumnIndex As Integer
Valore della proprietà
Indice di colonna della cella modificata.
Esempio
Nell'esempio di codice seguente viene illustrato l'utilizzo ColumnIndex di per individuare se la cella modificata si trova nella colonna 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
Commenti
Utilizzare la ColumnIndex proprietà per ottenere un indice nella Columns proprietà di un oggetto DataGridView.