web analytics

How to Create DataGridView with Equal Witdh Columns?

Options

codeling 1599 - 6654
@2018-03-04 09:11:35

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;

Comments

You must Sign In to comment on this topic.


© 2024 Digcode.com