DataGridView Automatic setting of row height column width

Source: Internet
Author: User

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);

  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.