DataGridViewColumn.GetPreferredWidth(DataGridViewAutoSizeColumnMode, Boolean) DataGridViewColumn.GetPreferredWidth(DataGridViewAutoSizeColumnMode, Boolean) DataGridViewColumn.GetPreferredWidth(DataGridViewAutoSizeColumnMode, Boolean) DataGridViewColumn.GetPreferredWidth(DataGridViewAutoSizeColumnMode, Boolean) Method

定义

根据指定条件计算列的理想宽度。Calculates the ideal width of the column based on the specified criteria.

public:
 virtual int GetPreferredWidth(System::Windows::Forms::DataGridViewAutoSizeColumnMode autoSizeColumnMode, bool fixedHeight);
public virtual int GetPreferredWidth (System.Windows.Forms.DataGridViewAutoSizeColumnMode autoSizeColumnMode, bool fixedHeight);
abstract member GetPreferredWidth : System.Windows.Forms.DataGridViewAutoSizeColumnMode * bool -> int
override this.GetPreferredWidth : System.Windows.Forms.DataGridViewAutoSizeColumnMode * bool -> int
Public Overridable Function GetPreferredWidth (autoSizeColumnMode As DataGridViewAutoSizeColumnMode, fixedHeight As Boolean) As Integer

参数

autoSizeColumnMode
DataGridViewAutoSizeColumnMode DataGridViewAutoSizeColumnMode DataGridViewAutoSizeColumnMode DataGridViewAutoSizeColumnMode

一个 DataGridViewAutoSizeColumnMode 值,该值指定自动调整大小模式。A DataGridViewAutoSizeColumnMode value that specifies an automatic sizing mode.

fixedHeight
Boolean Boolean Boolean Boolean

如果根据当前行高计算列宽度,则为 true;如果根据可变行高计算列宽度,则为 falsetrue to calculate the width of the column based on the current row heights; false to calculate the width with the expectation that the row heights will be adjusted.

返回

该列的理想宽度(以像素为单位)。The ideal width, in pixels, of the column.

异常

autoSizeColumnModeNotSetNoneFillautoSizeColumnMode is NotSet, None, or Fill.

注解

DataGridView控件的基于内容的自动调整大小功能将使用此属性来确定列的理想宽度。This property is used by the content-based automatic sizing feature of the DataGridView control to determine the ideal width of a column.

的参数值基于计算行高度计算列宽,这将实现理想的单元格高度与宽度的比率。false fixedHeightA fixedHeight parameter value of false calculates the column width based on calculated row heights that will achieve ideal cell height-to-width ratios. 若要将单元格内容换行到多行,对单元格有效的单元格样式WrapMode必须具有属性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.

有关自动调整大小的详细信息,请参阅Windows 窗体 DataGridView 控件中的调整大小选项For more information about automatic sizing, see Sizing Options in the Windows Forms DataGridView Control.

适用于

另请参阅