DataGridViewColumn.FillWeight Property

Definition

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.

C#
public float FillWeight { get; set; }

Property Value

A Single representing the width of the column when it is in fill mode relative to the widths of other fill-mode columns. The default is 100.

Exceptions

The specified value when setting this property is less than or equal to 0.

Examples

The following code example illustrates the use of this property. This example is part of a larger example available in How to: Set the Sizing Modes of the Windows Forms DataGridView Control.

C#
dataGridView1.AutoSizeColumnsMode =
    DataGridViewAutoSizeColumnsMode.Fill;

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;

Remarks

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. All fill-mode columns in the control divide the available space in proportions determined by their FillWeight property values. For more information about column fill mode, see Column Fill Mode in the Windows Forms DataGridView Control.

The maximum sum of FillWeight values for all columns in a DataGridView control is 65535.

Applies to

Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

See also