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

參數

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. 若要將資料格內容包裝到多行,資料格的有效儲存格樣式必須具有WrapModeTrue屬性值。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 Forms DataGridView 控制項中的調整大小選項For more information about automatic sizing, see Sizing Options in the Windows Forms DataGridView Control.

適用於

另請參閱