DataGridViewComboBoxCell.GetFormattedValue メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > DataGridViewComboBoxCell.GetFormattedValue メソッドの意味・解説 

DataGridViewComboBoxCell.GetFormattedValue メソッド

メモ : このメソッドは、.NET Framework version 2.0 で新しく追加されたものです。

セルのデータの書式指定済みの値を取得します。

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

Protected Overrides Function
 GetFormattedValue ( _
    value As Object, _
    rowIndex As Integer, _
    ByRef cellStyle As DataGridViewCellStyle,
 _
    valueTypeConverter As TypeConverter, _
    formattedValueTypeConverter As TypeConverter, _
    context As DataGridViewDataErrorContexts _
) As Object
Dim value As Object
Dim rowIndex As Integer
Dim cellStyle As DataGridViewCellStyle
Dim valueTypeConverter As TypeConverter
Dim formattedValueTypeConverter As TypeConverter
Dim context As DataGridViewDataErrorContexts
Dim returnValue As Object

returnValue = Me.GetFormattedValue(value, rowIndex, cellStyle,
 valueTypeConverter, formattedValueTypeConverter, context)
protected override Object GetFormattedValue (
    Object value,
    int rowIndex,
    ref DataGridViewCellStyle cellStyle,
    TypeConverter valueTypeConverter,
    TypeConverter formattedValueTypeConverter,
    DataGridViewDataErrorContexts context
)
protected:
virtual Object^ GetFormattedValue (
    Object^ value, 
    int rowIndex, 
    DataGridViewCellStyle^% cellStyle, 
    TypeConverter^ valueTypeConverter, 
    TypeConverter^ formattedValueTypeConverter, 
    DataGridViewDataErrorContexts context
) override
protected Object GetFormattedValue (
    Object value, 
    int rowIndex, 
    /** @ref */ DataGridViewCellStyle cellStyle, 
    TypeConverter valueTypeConverter, 
    TypeConverter formattedValueTypeConverter, 
    DataGridViewDataErrorContexts context
)
JScript では、値型の引数は参照渡しされません。

パラメータ

value

書式指定される値。

rowIndex

セルの親行のインデックス。

cellStyle

セルに反映される DataGridViewCellStyle。

valueTypeConverter

書式指定済みの値の型へカスタムの変換を実行する、元の値の型に関連付けられた TypeConverter。カスタムの変換が不要な場合は null 参照 (Visual Basic では Nothing)。

formattedValueTypeConverter

書式指定済みの値の型からカスタムの変換を実行する、その値の型に関連付けられた TypeConverter。カスタムの変換が不要な場合は null 参照 (Visual Basic では Nothing)。

context

書式指定済みの値が必要とされているコンテキストを示す DataGridViewDataErrorContexts 値のビットごとの組み合わせ。

戻り値
書式指定適用後のセルのデータの値。セルが DataGridView コントロールに含まれていない場合は null 参照 (Visual Basic では Nothing)。

例外例外
例外の種類条件

Exception

書式指定が失敗し、DataGridView コントロールの DataError イベントのハンドラが定義されていないか、ハンドラで ThrowException プロパティが true に設定されました。この例外オブジェクトは、通常、型変換エラーの場合は FormatException 型、value が DataSource または Items コレクションに存在しない場合は ArgumentException 型にキャストできます。

解説解説

DataGridView コントロールは、このメソッドを呼び出して、FormattedValueType プロパティで示される型の等価な表示用の値にセル値を変換します。コントロールは、セル値をこのメソッドの value パラメータに渡します。

このメソッドは、まず、次のいずれかの条件が満たされているかを調べることによって、value が有効であるかを確認します。

value が有効でない場合、DataGridView.DataError イベントが発生します。このイベントのハンドラがない場合や、ハンドラで DataGridViewDataErrorEventArgs.ThrowException プロパティを true に設定している場合、例外がスローされます。

value が有効であり、DataError イベントのハンドラが存在していて、なおかつ、DataGridViewDataErrorEventArgs.ThrowException プロパティが true に設定されている場合、DataGridView.CellFormatting イベントが発生します。

CellFormatting イベント ハンドラで、value と cellStyle の両方を変更できます。ただし、ハンドラが DataGridViewCellFormattingEventArgs.FormattingApplied プロパティを true に設定していない場合、このメソッドは、cellStyle オブジェクトの書式指定のプロパティを使用して、value の書式を設定します。これにより、別途 DataError イベントが発生する場合があります。

書式指定に成功した場合は、DataGridView コントロールで表示される書式指定済みの値が返されます。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DataGridViewComboBoxCell クラス
DataGridViewComboBoxCell メンバ
System.Windows.Forms 名前空間
FormattedValueType
DataSource
Items
DataGridView クラス
DataGridViewCellStyle クラス
TypeConverter
DataGridViewDataErrorContexts
DataGridViewCellStyle.Format プロパティ
DataGridView.CellFormatting イベント
DataGridView.DataError イベント
DataGridViewCell.GetFormattedValue
ParseFormattedValue



英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

DataGridViewComboBoxCell.GetFormattedValue メソッドのお隣キーワード
検索ランキング

   

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



DataGridViewComboBoxCell.GetFormattedValue メソッドのページの著作権

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

©2026 GRAS Group, Inc.RSS