DataGridViewRow.GetPreferredHeight メソッド
アセンブリ: 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
戻り値
行の適切な高さ (ピクセル単位)。


このプロパティは、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; }

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DataGridViewRow クラス
DataGridViewRow メンバ
System.Windows.Forms 名前空間
DataGridView クラス
DataGridViewAutoSizeRowMode 列挙体
DataGridViewCellStyle.WrapMode プロパティ
GetPreferredWidth
その他の技術情報
方法 : Windows フォームの DataGridView コントロールの行の外観をカスタマイズする
Windows フォーム DataGridView コントロールのサイズ変更オプション
Windows フォーム DataGridView コントロールを拡張するための推奨される手順
- DataGridViewRow.GetPreferredHeight メソッドのページへのリンク