DataGridView.CellParsing イベントとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > DataGridView.CellParsing イベントの意味・解説 

DataGridView.CellParsing イベント

メモ : このイベントは、.NET Framework version 2.0新しく追加されたものです。

セルの値が変更され場合セル編集モード終了したときに発生します

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Public Event CellParsing As
 DataGridViewCellParsingEventHandler
Dim instance As DataGridView
Dim handler As DataGridViewCellParsingEventHandler

AddHandler instance.CellParsing, handler
public event DataGridViewCellParsingEventHandler CellParsing
public:
event DataGridViewCellParsingEventHandler^ CellParsing {
    void add (DataGridViewCellParsingEventHandler^ value);
    void remove (DataGridViewCellParsingEventHandler^ value);
}
/** @event */
public void add_CellParsing (DataGridViewCellParsingEventHandler
 value)

/** @event */
public void remove_CellParsing (DataGridViewCellParsingEventHandler
 value)
JScript では、イベント使用できますが、新規に宣言することはできません。
解説解説

既定では、DataGridView コントロールは、セル表示されるユーザー指定の値を、セルValueType プロパティ指定された型の実際の基になるセル値に変換しようとします。この変換は、セルの InheritedStyle プロパティによって返されセル スタイル書式指定プロパティ使用します

標準変換要件満たしてない場合は、CellParsing イベント処理して必要な型へのカスタム変換指定します

ユーザーは、EditMode プロパティ指定されメソッド使用して編集モード開始し別のセル移動するか、Enter キー押して編集モード終了し変更セルコミットます。Esc キーを押すと、変更コミット前の値に戻りCellParsing イベント発生しません。CellParsing イベントは、最後の値が元の値と同じであってもセルの値が実際に変更され場合にだけ発生します。CommitEdit メソッド呼び出されたときにも発生します

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

値を自分変換する場合は、ConvertEventArgs.Value プロパティ書式設定された最初の値を、セルValueType プロパティ指定された型の変換後の値に置換します。解析不要になったことを指定するには、DataGridViewCellParsingEventArgs.ParsingApplied プロパティtrue設定します

イベント ハンドラ完了したときに、ConvertEventArgs.Valuenull 参照 (Visual Basic では Nothing) になっているか、正しい型ではない場合、または DataGridViewCellParsingEventArgs.ParsingApplied プロパティfalse場合Value は、セルParseFormattedValue メソッド既定の型コンバータ使用して解析されます。このメソッド既定実装は、渡されセル スタイルNullValueDataSourceNullValue、および FormatProvider の各プロパティ使用して値を解析します。値が NullValueない場合、その値は、渡されFormatProvider プロパティと型コンバータ使用して解析されます。

セル値を、表示合わせて書式設定された値に変換するときにカスタマイズを行うには、CellFormatting イベント処理します

イベント処理詳細については、「イベント利用」を参照してください

使用例使用例

CellParsing イベント処理する方法次のコード例示します。この例では、DataGridViewCellParsingEventArgs クラス使用方法示します

' 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;
            }
         }
      }
   }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DataGridView クラス
DataGridView メンバ
System.Windows.Forms 名前空間
DataGridView.CellParsing イベント
OnCellParsing
CommitEdit
DataGridView.CellFormatting イベント
DataGridView.EditMode プロパティ
DataGridViewCell.ValueType
DataGridViewCell.InheritedStyle
DataGridViewCell.ParseFormattedValue
DataGridViewCellParsingEventHandler
DataGridViewCellParsingEventArgs
DataGridViewCellParsingEventArgs.InheritedCellStyle
DataGridViewCellParsingEventArgs.ParsingApplied
ConvertEventArgs.Value プロパティ
DataGridViewCellStyle
DataGridViewCellStyle.NullValue
DataGridViewCellStyle.Format
DataGridViewCellStyle.FormatProvider
その他の技術情報
Windows フォーム DataGridView コントロールでのセルスタイル
DataGridView コントロール (Windows フォーム)



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「DataGridView.CellParsing イベント」の関連用語

DataGridView.CellParsing イベントのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



DataGridView.CellParsing イベントのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS