I would like to know how to set the width of columns of DataGridView
manually.
My first column must have a fixed value and the other columns must "fill" the grid, so that they are the same size.
I would like to know how to set the width of columns of DataGridView
manually.
My first column must have a fixed value and the other columns must "fill" the grid, so that they are the same size.
First click on the little box in the upper right corner of DataGridView
and click Edit Columns . This will open a form with all the columns of your Grid, so you select in the column that wants to leave the fixed size ( TESTE1
in that case) and sets the value of the Width
property on the right side of the screen.
Then you only need to change the AutoSizeMode
property of all other columns to Fill
.
Yousaidyoucreatethecolumnsdynamically,whichmakesitimpossibleforyoutodowhatIsaidabove.ThesolutionwouldbetoiteratethroughtheDataGridView
columnsandsetthesizesafterthegridispopulated.
foreach(DataGridViewColumncolumnindgNotas.Columns){if(column.DataPropertyName=="primeiraColuna")
column.Width = 100; //tamanho fixo da primeira coluna
column.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}