DataGridViewCellParsingEventArgs.ColumnIndex プロパティ
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

変更されたセルの列インデックス。


ColumnIndex を使用して、変更されたセルが日付列にあるかどうかを検出する方法を次のコード例に示します。
' 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
// 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. 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 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- DataGridViewCellParsingEventArgs.ColumnIndex プロパティのページへのリンク