I have a WinForms application with DataGridView
control. My control has five columns (say "Name", "Address", "Phone" etc)
I am not happy with default column width. I want to have more control over column appearance. What I want is to be able to do one of the following:
Please suggest - which property to use and how.
To adjust column widths programmatically, use the AutoResizeColumn or AutoResizeColumns methods or set the column Width property. For more information about content-based automatic sizing, see Sizing Options in the Windows Forms DataGridView Control.
To create fill-mode columns for values of varying size and importance. Set the DataGridView. AutoSizeColumnsMode property to Fill to set the sizing mode for all columns that do not override this value. Set the FillWeight properties of the columns to values that are proportional to their average content widths.
Set the property AutoSizeColumnsMode to be Fill . That'll ensure your columns stretch to 100% within your DataGridView. The columns will stretch/shrink when you resize your grid (if your grid is anchored to your form). Show activity on this post.
You can use the DataGridViewColumn.Width
property to do it:
DataGridViewColumn column = dataGridView.Columns[0]; column.Width = 60;
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcolumn.width.aspx
The following also can be tried:
DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells
or use the other setting options in the DataGridViewAutoSizeColumnsMode Enum
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With