Automatic adjustment column width setting of DataGridView in C# Winform

The automatic adjustment column width setting property of DataGridView in C#Winform is AutoSizeColumnMode

The enumeration values ​​are as follows:

1. AllCells adjusts the column width to fit the contents of all cells in the column, including header cells.  
2. AllCellsExceptHeader adjusts the column width to fit the contents of all cells in the column, excluding header cells.  
3. ColumnHeader adjusts the column width to fit the content of the column header cell.  
4. DisplayedCells adjusts the column width to fit the contents of all cells in the column of the row displayed on the current screen, including the header cell.  
5. DisplayedCellsExceptHeader adjusts the column width to fit the content of all cells in the column of the row displayed on the current screen, excluding the header cell.  
6. Fill adjusts the column width so that the width of all columns just fills the display area of ​​the control. You only need to scroll horizontally to ensure that the column width is above the value of the DataGridViewColumn.MinimumWidth property. The relative column width is determined by the relative DataGridViewColumn.FillWeight property value.  
7. The column width of None will not be adjusted automatically.  
8. The resizing behavior of the NotSet column is inherited from the DataGridView.AutoSizeColumnsMode property.

Make corresponding settings according to the actual situation.

Guess you like

Origin blog.csdn.net/qq_30725967/article/details/132250084