DataGridViewAutoSizeColumnsMode DataGridViewAutoSizeColumnsMode DataGridViewAutoSizeColumnsMode DataGridViewAutoSizeColumnsMode Enum

定义

定义用于指定如何调整列宽的值。Defines values for specifying how the widths of columns are adjusted.

public enum class DataGridViewAutoSizeColumnsMode
public enum DataGridViewAutoSizeColumnsMode
type DataGridViewAutoSizeColumnsMode = 
Public Enum DataGridViewAutoSizeColumnsMode
继承
DataGridViewAutoSizeColumnsModeDataGridViewAutoSizeColumnsModeDataGridViewAutoSizeColumnsModeDataGridViewAutoSizeColumnsMode

字段

AllCells AllCells AllCells AllCells 6

列宽调整到适合列中所有单元格(包括标头单元格)的内容。The column widths adjust to fit the contents of all cells in the columns, including header cells.

AllCellsExceptHeader AllCellsExceptHeader AllCellsExceptHeader AllCellsExceptHeader 4

列宽调整到适合列中除标头单元格以外所有单元格的内容。The column widths adjust to fit the contents of all cells in the columns, excluding header cells.

ColumnHeader ColumnHeader ColumnHeader ColumnHeader 2

列宽调整到适合列标头单元格的内容。The column widths adjust to fit the contents of the column header cells.

DisplayedCells DisplayedCells DisplayedCells 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 DisplayedCellsExceptHeader DisplayedCellsExceptHeader 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 Fill Fill 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 None None 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. 在此示例中,主控件的列大小调整模式为无,并以编程方式初始化的列宽度,以适应加载的值。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). 此示例中提供一个更大示例摘自如何: 创建母版/详细信息窗体使用两个 Windows 窗体 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 窗体 DataGridView 控件中的大小调整选项For more information about sizing modes, see Sizing Options in the Windows Forms DataGridView Control. 有关列填充模式的详细信息,请参见Windows 窗体 DataGridView 控件中的列填充模式For more information about column fill mode in particular, see Column Fill Mode in the Windows Forms DataGridView Control.

适用于

另请参阅