Share via


DataGridViewRow.GetPreferredHeight 메서드

정의

지정된 조건에 따라 지정된 행의 이상적인 높이를 계산합니다.

public:
 virtual int GetPreferredHeight(int rowIndex, System::Windows::Forms::DataGridViewAutoSizeRowMode autoSizeRowMode, bool fixedWidth);
public virtual int GetPreferredHeight (int rowIndex, System.Windows.Forms.DataGridViewAutoSizeRowMode autoSizeRowMode, bool fixedWidth);
abstract member GetPreferredHeight : int * System.Windows.Forms.DataGridViewAutoSizeRowMode * bool -> int
override this.GetPreferredHeight : int * System.Windows.Forms.DataGridViewAutoSizeRowMode * bool -> int
Public Overridable Function GetPreferredHeight (rowIndex As Integer, autoSizeRowMode As DataGridViewAutoSizeRowMode, fixedWidth As Boolean) As Integer

매개 변수

rowIndex
Int32

기본 설정 높이가 계산되는 행의 인덱스입니다.

autoSizeRowMode
DataGridViewAutoSizeRowMode

자동 크기 조정 모드를 지정하는 DataGridViewAutoSizeRowMode입니다.

fixedWidth
Boolean

고정 셀 너비의 기본 설정 높이를 계산하려면 true이고, 그렇지 않으면 false입니다.

반환

Int32

행의 이상적인 높이(픽셀)입니다.

예외

autoSizeRowMode는 유효한 DataGridViewAutoSizeRowMode 값이 아닙니다.

rowIndex가 유효 범위인 0부터 컨트롤의 행 수에서 1을 뺀 값 사이에 있지 않은 경우

예제

다음 코드 예제에서는 크기가 조정된 행에 대한 새 안쪽 여백을 결정하는 방법을 사용합니다 GetPreferredHeight . 이 코드 예제는에서 제공 하는 더 큰 예제의 일부입니다 방법: Windows Forms 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.
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;
}
' 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

설명

이 속성은 컨트롤의 콘텐츠 기반 자동 크기 조정 기능에서 행의 DataGridView 이상적인 높이를 결정하는 데 사용됩니다. 이 rowIndex 값을 사용하면 공유 행의 실제 행 인덱스(index)를 지정할 수 있습니다. (공유 행의 속성 값은 Index -1입니다.)

매개 변수 값 falsefixedWidth 이상적인 셀 높이 대 너비 비율을 얻을 수 있는 계산된 열 너비에 따라 행 높이를 계산합니다.

셀 내용을 여러 줄로 래핑하려면 셀에 적용되는 셀 스타일에 속성 값TrueWrapMode 있어야 합니다.

자동 크기 조정에 대한 자세한 내용은 Windows Forms DataGridView 컨트롤의 크기 조정 옵션을 참조하세요.

적용 대상

추가 정보