Upravit

Sdílet prostřednictvím


DataGridViewColumn.GetPreferredWidth Method

Definition

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

Parameters

autoSizeColumnMode
DataGridViewAutoSizeColumnMode

A DataGridViewAutoSizeColumnMode value that specifies an automatic sizing mode.

fixedHeight
Boolean

true 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.

Returns

The ideal width, in pixels, of the column.

Exceptions

autoSizeColumnMode is NotSet, None, or Fill.

autoSizeColumnMode is not a valid DataGridViewAutoSizeColumnMode value.

Remarks

This property is used by the content-based automatic sizing feature of the DataGridView control to determine the ideal width of a column.

A fixedHeight parameter value of false calculates the column width based on calculated row heights that will achieve ideal cell height-to-width ratios. For cell contents to wrap onto multiple lines, the cell style in effect for the cell must have a WrapMode property value of True.

For more information about automatic sizing, see Sizing Options in the Windows Forms DataGridView Control.

Applies to

See also