DataGridViewColumn.FillWeight 属性


获取或设置一个值,表示当该列处于填充模式时,相对于控件中处于填充模式的其他列的宽度。Gets or sets a value that represents the width of the column when it is in fill mode relative to the widths of other fill-mode columns in the control.

 property float FillWeight { float get(); void set(float value); };
public float FillWeight { get; set; }
member this.FillWeight : single with get, set
Public Property FillWeight As Single


Single,表示当该列处于填充模式时,相对于控件中处于填充模式的其他列的宽度。A Single representing the width of the column when it is in fill mode relative to the widths of other fill-mode columns. 默认值为 100。The default is 100.


设置此属性时,指定的值小于或等于 0。The specified value when setting this property is less than or equal to 0.


下面的代码示例演示如何使用此属性。The following code example illustrates the use of this property. 此示例摘自如何:设置 Windows 窗体 DataGridView 控件的大小调整模式中提供的更大示例的一部分。This example is part of a larger example available in How to: Set the Sizing Modes of the Windows Forms DataGridView Control.

dataGridView1.AutoSizeColumnsMode =

DataGridViewTextBoxColumn subTitleColumn =
    new DataGridViewTextBoxColumn();
subTitleColumn.HeaderText = "Subtitle";
subTitleColumn.MinimumWidth = 50;
subTitleColumn.FillWeight = 100;

DataGridViewTextBoxColumn summaryColumn =
    new DataGridViewTextBoxColumn();
summaryColumn.HeaderText = "Summary";
summaryColumn.MinimumWidth = 50;
summaryColumn.FillWeight = 200;

DataGridViewTextBoxColumn contentColumn =
    new DataGridViewTextBoxColumn();
contentColumn.HeaderText = "Content";
contentColumn.MinimumWidth = 50;
contentColumn.FillWeight = 300;
dataGridView1.AutoSizeColumnsMode = _

Dim subTitleColumn As new DataGridViewTextBoxColumn()
subTitleColumn.HeaderText = "Subtitle"
subTitleColumn.MinimumWidth = 50
subTitleColumn.FillWeight = 100

Dim summaryColumn As new DataGridViewTextBoxColumn()
summaryColumn.HeaderText = "Summary"
summaryColumn.MinimumWidth = 50
summaryColumn.FillWeight = 200

Dim contentColumn As new DataGridViewTextBoxColumn()
contentColumn.HeaderText = "Content"
contentColumn.MinimumWidth = 50
contentColumn.FillWeight = 300


FillInheritedAutoSizeMode 属性值时,该列将与该模式中的其他列一起调整,以便控件中的所有可见列都完全填充可用显示区域的水平宽度。When the InheritedAutoSizeMode property value is Fill, the column is resized along with other columns in that mode so that all visible columns in the control exactly fill the horizontal width of the available display area. 控件中的所有填充模式列都按其 FillWeight 属性值确定的比例划分可用空间。All fill-mode columns in the control divide the available space in proportions determined by their FillWeight property values. 有关列填充模式的详细信息,请参阅Windows 窗体 DataGridView 控件中的列填充模式For more information about column fill mode, see Column Fill Mode in the Windows Forms DataGridView Control.

DataGridView 控件中所有列 FillWeight 值的最大值为65535。The maximum sum of FillWeight values for all columns in a DataGridView control is 65535.