DataGridViewAutoSizeColumnsMode 列舉

定義

定義值來指定要如何調整資料行的寬度。Defines values for specifying how the widths of columns are adjusted.

public enum class DataGridViewAutoSizeColumnsMode
public enum DataGridViewAutoSizeColumnsMode
type DataGridViewAutoSizeColumnsMode = 
Public Enum DataGridViewAutoSizeColumnsMode
繼承
DataGridViewAutoSizeColumnsMode

欄位

AllCells 6

資料行寬度會調整,以適合資料行中的所有儲存格的內容 (包括標題儲存格)。The column widths adjust to fit the contents of all cells in the columns, including header cells.

AllCellsExceptHeader 4

資料行寬度會調整,以適合資料行中的所有儲存格的內容 (不包括標題儲存格)。The column widths adjust to fit the contents of all cells in the columns, excluding header cells.

ColumnHeader 2

資料行寬度會調整,以適合資料行行首儲存格的內容。The column widths adjust to fit the contents of the column header cells.

DisplayedCells 10

資料行寬度會調整,以適合資料行中的所有儲存格的內容 (位在目前顯示在螢幕上的資料列中),包括標題儲存格。The column widths adjust to fit the contents of all cells in the columns that are in rows currently displayed onscreen, including header cells.

DisplayedCellsExceptHeader 8

資料行寬度會調整,以適合資料行中的所有儲存格的內容 (位在目前顯示在螢幕上的資料列中),不包括標題儲存格。The column widths adjust to fit the contents of all cells in the columns that are in rows currently displayed onscreen, excluding header cells.

Fill 16

資料行寬度會調整,使得所有資料行的寬度可以剛好填滿控制項的顯示區,且必須要使用水平捲動方式,才能讓資料行寬度維持在 MinimumWidth 屬性值之上。The column widths adjust so that the widths of all columns exactly fill the display area of the control, requiring horizontal scrolling only to keep column widths above the MinimumWidth property values. 相對的資料行寬度是由相對的 FillWeight 屬性值所決定。Relative column widths are determined by the relative FillWeight property values.

None 1

資料行寬度不會自動調整。The column widths do not automatically adjust.

範例

下列程式碼範例說明在主要/詳細資料案例中使用這個列舉,其中兩個 DataGridView 控制項會在父/子關聯性中顯示兩個數據表的資料。The following code example illustrates the use of this enumeration in a master/details scenario where two DataGridView controls display data from two tables in a parent/child relationship. 在此範例中,主控制項的資料行調整大小模式為 None,而資料行寬度則以程式設計方式初始化,以符合載入的值。In this example, the column sizing mode for the master control is None and the column widths are programmatically initialized to fit the loaded values. 詳細資料控制項會設定為自動調整大小模式,以便在每次值變更時(例如,當使用者變更父資料表中的目前資料列)時,將會自動調整資料行。The details control is set to an automatic sizing mode so that columns will adjust automatically whenever the values change (for example, when the user changes the current row in the parent table). 這個範例是 how to:使用兩個 Windows Forms DataGridView 控制項建立主要/詳細表單中所提供的較大範例的一部分。This example is part of a larger example available in How to: Create a Master/Detail Form Using Two Windows Forms DataGridView Controls.

private void Form1_Load(object sender, System.EventArgs e)
{
    // Bind the DataGridView controls to the BindingSource
    // components and load the data from the database.
    masterDataGridView.DataSource = masterBindingSource;
    detailsDataGridView.DataSource = detailsBindingSource;
    GetData();

    // Resize the master DataGridView columns to fit the newly loaded data.
    masterDataGridView.AutoResizeColumns();

    // Configure the details DataGridView so that its columns automatically
    // adjust their widths when the data changes.
    detailsDataGridView.AutoSizeColumnsMode = 
        DataGridViewAutoSizeColumnsMode.AllCells;
}
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) _
    Handles Me.Load

    ' Bind the DataGridView controls to the BindingSource
    ' components and load the data from the database.
    masterDataGridView.DataSource = masterBindingSource
    detailsDataGridView.DataSource = detailsBindingSource
    GetData()

    ' Resize the master DataGridView columns to fit the newly loaded data.
    masterDataGridView.AutoResizeColumns()

    ' Configure the details DataGridView so that its columns automatically
    ' adjust their widths when the data changes.
    detailsDataGridView.AutoSizeColumnsMode = _
        DataGridViewAutoSizeColumnsMode.AllCells

End Sub

備註

DataGridView 控制項可以調整其資料行的大小,使其填滿控制項的可用水準寬度,或使其顯示所有儲存格或指定資料格的完整內容。The DataGridView control can resize its columns to make them fill the available horizontal width of the control or to make them display the full contents of all cells or of specified cells.

使用 Fill 模式時,資料行的慣用寬度是藉由調整該模式中所有資料行的大小來決定,讓控制項中的所有可見資料行完全填滿可用顯示區域的水準寬度。With Fill mode, the preferred width of a column is determined by resizing all columns in that mode so that all visible columns in the control exactly fill the horizontal width of the available display area. 使用其他模式時,慣用的資料行寬度是顯示所有資料格的最大寬度,或該資料行中資料格子集所需的最小寬度,例如目前顯示之資料列中的儲存格子集。With other modes, the preferred column width is the minimum width required to display the largest cell value from all cells or a subset of cells in that column, such as the subset of cells that are in currently displayed rows. 使用資料格子集來判斷新的寬度有助於避免在使用多個資料列時產生效能上的負面影響。Using a subset of cells to determine the new width is useful to avoid a performance penalty when working with many rows of data.

以內容為基礎的自動調整大小,可防止使用者使用滑鼠來調整資料行寬度。Content-based automatic resizing prevents users from adjusting column widths with the mouse. 不過,使用者調整大小是在填滿模式中啟用。User resizing is enabled in fill mode, however.

DataGridView 控制項 AutoSizeColumnsMode 屬性和 AutoResizeColumns 方法會使用這個列舉。This enumeration is used by the DataGridView control AutoSizeColumnsMode property and AutoResizeColumns method.

如需調整大小模式的詳細資訊,請參閱Windows Forms DataGridView 控制項中的調整大小選項For more information about sizing modes, see Sizing Options in the Windows Forms DataGridView Control. 如需特定資料行填滿模式的詳細資訊,請參閱Windows Forms DataGridView 控制項中的資料行填滿模式For more information about column fill mode in particular, see Column Fill Mode in the Windows Forms DataGridView Control.

適用於

另請參閱