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

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

DataGridViewRow.GetPreferredHeight メソッド

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

指定した基準に基づいて、指定した行の適切な高さを計算します。

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

Public Overridable Function
 GetPreferredHeight ( _
    rowIndex As Integer, _
    autoSizeRowMode As DataGridViewAutoSizeRowMode, _
    fixedWidth As Boolean _
) As Integer
Dim instance As DataGridViewRow
Dim rowIndex As Integer
Dim autoSizeRowMode As DataGridViewAutoSizeRowMode
Dim fixedWidth As Boolean
Dim returnValue As Integer

returnValue = instance.GetPreferredHeight(rowIndex, autoSizeRowMode, fixedWidth)
public virtual int GetPreferredHeight (
    int rowIndex,
    DataGridViewAutoSizeRowMode autoSizeRowMode,
    bool fixedWidth
)
public:
virtual int GetPreferredHeight (
    int rowIndex, 
    DataGridViewAutoSizeRowMode autoSizeRowMode, 
    bool fixedWidth
)
public int GetPreferredHeight (
    int rowIndex, 
    DataGridViewAutoSizeRowMode autoSizeRowMode, 
    boolean fixedWidth
)
public function GetPreferredHeight (
    rowIndex : int, 
    autoSizeRowMode : DataGridViewAutoSizeRowMode, 
    fixedWidth : boolean
) : int

パラメータ

rowIndex

適切な高さを計算する行のインデックス。

autoSizeRowMode

自動サイズ設定モードを指定する DataGridViewAutoSizeRowMode。

fixedWidth

固定のセル幅に対する適切な高さを計算する場合は true。それ以外の場合は false。

戻り値
行の適切な高さ (ピクセル単位)。

例外例外
例外の種類条件

InvalidEnumArgumentException

autoSizeRowMode が有効な DataGridViewAutoSizeRowMode 値ではありません。

ArgumentOutOfRangeException

rowIndex が有効な範囲 (0 ~ コントロールの行数 - 1) 内にありません。

解説解説

このプロパティは、DataGridView コントロールの、内容に基づく自動サイズ変更機能で、行の適切な高さを決定するために使用されます。rowIndex の値を使用して、共有行の実際の行インデックスを指定できます(共有行の Index プロパティ値は -1 です)。

fixedWidth パラメータ値を false にすると、セルの幅に対する高さの比率が理想的となるような列幅の計算値に基づいて、行の高さを計算します。

セルの内容が複数の行に折り返されるようにするには、セルに対して有効なセル スタイルの WrapMode プロパティ値を True に設定する必要があります。

自動サイズ変更の詳細については、「Windows フォーム DataGridView コントロールのサイズ変更オプション」を参照してください。

使用例使用例

GetPreferredHeight メソッドを使用して、サイズ変更された行の新しい埋め込みを決定するコード例を次に示します。次のコード例は、「方法 : Windows フォームの DataGridView コントロールの行の外観をカスタマイズする」で示されている例の一部です。

' Adjusts the padding when the user changes the row height so that 
' the normal cell content is fully displayed and any extra
' height is used for the content that spans multiple columns.
Sub dataGridView1_RowHeightChanged(ByVal sender
 As Object, _
    ByVal e As DataGridViewRowEventArgs) _
    Handles dataGridView1.RowHeightChanged

    ' Calculate the new height of the normal cell content.
    Dim preferredNormalContentHeight As Int32
 = _
        e.Row.GetPreferredHeight(e.Row.Index, _
        DataGridViewAutoSizeRowMode.AllCellsExceptHeader, True)
 - _
        e.Row.DefaultCellStyle.Padding.Bottom()

    ' Specify a new padding.
    Dim newPadding As Padding = e.Row.DefaultCellStyle.Padding
    newPadding.Bottom = e.Row.Height - preferredNormalContentHeight
    e.Row.DefaultCellStyle.Padding = newPadding

End Sub
// Adjusts the padding when the user changes the row height so that
 
// the normal cell content is fully displayed and any extra
// height is used for the content that spans multiple columns.
void dataGridView1_RowHeightChanged(object sender,
    DataGridViewRowEventArgs e)
{
    // Calculate the new height of the normal cell content.
    Int32 preferredNormalContentHeight =
        e.Row.GetPreferredHeight(e.Row.Index, 
        DataGridViewAutoSizeRowMode.AllCellsExceptHeader, true)
 -
        e.Row.DefaultCellStyle.Padding.Bottom;

    // Specify a new padding.
    Padding newPadding = e.Row.DefaultCellStyle.Padding;
    newPadding.Bottom = e.Row.Height - preferredNormalContentHeight;
    e.Row.DefaultCellStyle.Padding = newPadding;
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

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

   

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



DataGridViewRow.GetPreferredHeight メソッドのページの著作権

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

©2026 GRAS Group, Inc.RSS