DataGridViewCellParsingEventArgs.ColumnIndex Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mendapatkan indeks kolom data sel yang memerlukan penguraian.
public:
property int ColumnIndex { int get(); };
public int ColumnIndex { get; }
member this.ColumnIndex : int
Public ReadOnly Property ColumnIndex As Integer
Nilai Properti
Indeks kolom sel yang diubah.
Contoh
Contoh kode berikut menunjukkan penggunaan ColumnIndex untuk menemukan apakah sel yang diubah berada di kolom tanggal.
// 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
Keterangan
ColumnIndex Gunakan properti untuk mendapatkan indeks ke Columns properti dari DataGridView.