DataGridViewCellParsingEventHandler 代理人

定義

CellParsingDataGridView イベントを処理するメソッドを表します。

public delegate void DataGridViewCellParsingEventHandler(System::Object ^ sender, DataGridViewCellParsingEventArgs ^ e);
public delegate void DataGridViewCellParsingEventHandler(object sender, DataGridViewCellParsingEventArgs e);
public delegate void DataGridViewCellParsingEventHandler(object? sender, DataGridViewCellParsingEventArgs e);
type DataGridViewCellParsingEventHandler = delegate of obj * DataGridViewCellParsingEventArgs -> unit
Public Delegate Sub DataGridViewCellParsingEventHandler(sender As Object, e As DataGridViewCellParsingEventArgs)

パラメーター

sender
Object

イベントのソース。

e
DataGridViewCellParsingEventArgs

イベント データを格納している DataGridViewCellParsingEventArgs

次のコード例では、 を使用してDataGridViewCellParsingEventHandler日付エントリの有効性をチェックします。

// 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

注釈

イベントを CellParsing 処理して、ユーザー指定の値から cell ValueType プロパティで指定された型の値へのカスタム値変換を提供します。

イベントを CellParsing 処理するときは、値を自分で変換することも、既定の変換をカスタマイズすることもできます。 たとえば、選択した型コンバーターを使用して cell ParseFormattedValue メソッドを使用して、自分で値を変換できます。 または、既定の型コンバーターで値を解析させ、セル InheritedStyle プロパティを使用して初期化される プロパティによってDataGridViewCellParsingEventArgs.InheritedCellStyle返されるオブジェクトの 、DataSourceNullValue、および FormatProvider プロパティを変更NullValueすることもできます。

値を自分で変換するときは、プロパティの最初の書式設定された値を ConvertEventArgs.Value 、セル ValueType プロパティで指定された型の変換された値に置き換えます。 これ以上解析する必要がないことを示すには、 プロパティを DataGridViewCellParsingEventArgs.ParsingAppliedtrue設定します。

イベント ハンドラーが完了すると、 がnull正しい型であるか、または プロパティfalseValueが の場合Valueは、 が既定の型ParsingAppliedコンバーターを使用してセル ParseFormattedValue メソッドを使用して解析されます。 このメソッドの既定の実装では、渡されたセル スタイルの NullValueDataSourceNullValue、および FormatProvider プロパティを使用して値を解析します。 値が と NullValue等しくない場合、値は プロパティと渡された型コンバーターを使用して FormatProvider 解析されます。

セル値を表示用の書式設定された値に変換するようにカスタマイズするには、 イベントを処理します CellFormatting

イベントを処理する方法の詳細については、次を参照してください。処理とイベントの発生します。

DataGridViewCellParsingEventHandler デリゲートを作成する場合は、イベントを処理するメソッドを指定します。 イベント ハンドラーにイベントを関連付けるには、イベントにデリゲートのインスタンスを追加します。 イベント ハンドラーは、デリゲートを削除しない限り、イベントが発生するたびに呼び出されます。 イベント ハンドラー デリゲートの詳細については、「イベントの 処理と発生」を参照してください。

拡張メソッド

GetMethodInfo(Delegate)

指定したデリゲートによって表されるメソッドを表すオブジェクトを取得します。

適用対象

こちらもご覧ください