How to Create DataGridView with Equal Witdh Columns? Options

codeling Posts: 1054 Points: 4431
Posted: Sunday, March 4, 2018 9:11:35 AM

the DataGridViewColumn.FillWeight property represents the width of the column when it is in fill mode relative to the widths of other fill-mode columns in the control. You use it to create equal width columns.

The following example create three columns with equal width in the DataGridView:

dataGridView1.AutoSizeColumnsMode =
    DataGridViewAutoSizeColumnsMode.Fill;

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

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

DataGridViewTextBoxColumn contentColumn =
    new DataGridViewTextBoxColumn();
contentColumn.HeaderText = "Content";
contentColumn.MinimumWidth = 100;
contentColumn.FillWeight = 100;

 
Users browsing this topic
Guest