Fit the columns header into a DGV, C #

1

Is there any way to embed the columns into a DGV so that it does not overlap (Follow the img as an example). Or Resize the DGV so that it shrinks to the required size of columns ? at runtime.

I'm using direct connection to DB so I do not see columns before execution.

    
asked by anonymous 24.09.2016 / 18:33

1 answer

2

You resolve this by accessing the AutoSizeMode property of each column. By default, columns have AutoSizeMode = NotSet . You will need to define at least one column as AutoSizeMode = Fill in conjunction with the FillWeight = 100 property.

Example:

this.dataGridView1.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
this.dataGridView1.Columns[1].FillWeight = 100;

Hug.

    
24.09.2016 / 19:07