1) Set the row height and column width automatic adjustment
[C #]
// settings include Automatic column width adjustment for header and all cells
= Datagridviewautosizecolumnsmode.allcells;
// settings include Row Height auto Adjustment for header and all cells
= Datagridviewautosizerowsmode.allcells;
Refer to MSDN Datagridviewautosizerowsmode instructions for setting value enumeration of the autoSizeColumnsMode property
2) Specify column or row AutoFit
[C #]
The first column is automatically adjusted
datagridview1.columns[0 = Datagridviewautosizecolumnmode.displayedcells;
< Span style= "line-height:normal; font-family:arial; " When >autosizemode is set to NotSet, the Datagridview.autosizecolumnsmode property is inherited by default.
< Span style= "line-height:normal; font-family:arial; " >3) Sets the height of the column header and the width of the wardrobe automatically adjusts
< Span style= "line-height:normal; font-family:arial; " > // set column header width can be freely adjusted
=
Datagridviewcolumnheadersheightsizemode.autosize;
< Span style= "line-height:normal; font-family:arial; " >
=
Datagridviewrowheaderswidthsizemode.autosizetoallheaders;
4) automatic adjustment at any time
A, temporary, let the column width adjust automatically, this is the same as specifying the autoSizeColumnsMode property.
< Span style= "line-height:normal; font-family:arial; " >< Span style= "Color:rgb (0, 0, 0); Line-height:normal; " > [C #]
Let all the columns of the DataGridView1 be adjusted automatically.
< Span style= "line-height:normal; font-family:arial; " > / /
datagridview1.autoresizecolumn ( 0
< Span style= "line-height:normal; font-family:arial; " > ) and datagridview1.autoresizecolumns (
b, temporary, let line height auto-adjust
< Span style= "Color:rgb (0, 128, 0); Line-height:normal; " > < Span style= "Color:rgb (0, 128, 0); Line-height:normal; " > //
< Span style= "Color:rgb (0, 128, 0); Line-height:normal; " > < Span style= "Color:rgb (0, 128, 0); Line-height:normal; " > / /
Datagridview1.autoresizerow (0, datagridviewautosizerowmode.allcells);
The above calledautoresizerowsAndAutoResizeRowWhen the specified isDataGridViewAutoSizeRowMode. When Allcells, the parameters can be omitted. ThatDataGridView1.AutoResizeRow(0) andDataGridView1.autoresizerows()
C, temporary, let the wardrobe and the column head automatically adjust
< Span style= "line-height:normal; Font-weight:bold; " > about performance:
when automatically adjusted by autoSizeColumnsMode or by the cells specified by the autoSizeRowsMode property, If the number of adjustments is too much then it can result in performance degradation, especially in the case of more rows and columns. In this case, replacing the allcells with Displayedcells can reduce the adjustment of non-visible cells, thus improving the performance.
< Span style= "line-height:normal; font-family:arial; " > < Span style= "Color:rgb (0, 0, 0); Line-height:normal; " > [C #]
< Span style= "Color:rgb (0, 0, 0); Line-height:normal; " > < Span style= "line-height:normal; font-family:arial; " > / / wardrobe width Auto adjust
Datagridview1.autoresizerowheaderswidth (
Datagridviewrowheaderswidthsizemode.autosizetoallheaders);