DataGridViewRow.GetPreferredHeight(Int32, DataGridViewAutoSizeRowMode, Boolean) Método
Definición
Calcula el alto ideal de la fila que se indica basándose en los criterios especificados.Calculates the ideal height of the specified row based on the specified criteria.
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
Parámetros
- rowIndex
- Int32
Índice de la fila de la que se calcula el alto preferido.The index of the row whose preferred height is calculated.
- autoSizeRowMode
- DataGridViewAutoSizeRowMode
DataGridViewAutoSizeRowMode que especifica un modo de tamaño automático.A DataGridViewAutoSizeRowMode that specifies an automatic sizing mode.
- fixedWidth
- Boolean
true
para calcular el alto preferido para un ancho de celda fijo; de lo contrario, false
.true
to calculate the preferred height for a fixed cell width; otherwise, false
.
Devoluciones
Alto ideal de la fila, en píxeles.The ideal height of the row, in pixels.
Excepciones
autoSizeRowMode
no es un valor DataGridViewAutoSizeRowMode válido.autoSizeRowMode
is not a valid DataGridViewAutoSizeRowMode value.
rowIndex
no está en el intervalo válido de 0 al número de filas del control menos 1.The rowIndex
is not in the valid range of 0 to the number of rows in the control minus 1.
Ejemplos
En el ejemplo de código siguiente se usa el GetPreferredHeight método para determinar el nuevo relleno de una fila cuyo tamaño se ha cambiado.The following code example uses the GetPreferredHeight method to determine the new padding for a row that has been resized. Este ejemplo de código forma parte de un ejemplo más grande que se proporciona en Cómo: personalizar la apariencia de las filas en el control DataGridView Windows Forms.This code example is part of a larger example provided in How to: Customize the Appearance of Rows in the Windows Forms DataGridView Control.
// 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
Comentarios
Esta propiedad la usa la característica de ajuste automático de tamaño basado en contenido del DataGridView control para determinar el alto ideal de una fila.This property is used by the content-based automatic sizing feature of the DataGridView control to determine the ideal height of a row. El rowIndex
valor permite especificar el índice de fila real de una fila compartida.The rowIndex
value lets you specify the actual row index of a shared row. (Las filas compartidas tienen Index valores de propiedad de-1).(Shared rows have Index property values of -1.)
Un fixedWidth
valor de parámetro de false
calcula el alto de la fila en función de los anchos de columna calculados que conseguirán las relaciones de alto y ancho de las celdas ideales.A fixedWidth
parameter value of false
calculates the row height based on calculated column widths that will achieve ideal cell height-to-width ratios.
Para que el contenido de la celda se ajuste en varias líneas, el estilo de celda en vigor para la celda debe tener un WrapMode valor de propiedad de True .For cell contents to wrap onto multiple lines, the cell style in effect for the cell must have a WrapMode property value of True.
Para obtener más información sobre el ajuste automático de tamaño, consulte Opciones de ajuste de tamaño en el control DataGridView Windows Forms.For more information about automatic sizing, see Sizing Options in the Windows Forms DataGridView Control.
Se aplica a
Consulte también
- DataGridView
- DataGridViewAutoSizeRowMode
- WrapMode
- GetPreferredWidth(DataGridViewAutoSizeColumnMode, Boolean)
- Procedimiento para personalizar la apariencia de las filas en el control DataGridView de formularios Windows FormsHow to: Customize the Appearance of Rows in the Windows Forms DataGridView Control
- Opciones de ajuste de tamaño en el control DataGridView de formularios Windows FormsSizing Options in the Windows Forms DataGridView Control
- Procedimientos recomendados para ajustar la escala del control DataGridView en formularios Windows FormsBest Practices for Scaling the Windows Forms DataGridView Control