DataGridView Five: Automatically set column width and row height

Source: Internet
Author: User

First, set the row height and the width of the automatic adjustment

Set the automatic adjustment of column widths including header and all cells

1 // set the automatic adjustment of column widths including header and all cells 2 this. Dgv_propdemo.autosizecolumnsmode = Datagridviewautosizecolumnsmode.allcells;

Set row height auto-adjustment including header and all cells

1 // Set row height auto-adjustment including header and all cells 2 this. Dgv_propdemo.autosizerowsmode = Datagridviewautosizerowsmode.allcells;

Set the first column to auto-adjust

1 // The first column is automatically adjusted 2 this. dgv_propdemo.columns[0]. AutoSizeMode = Datagridviewautosizecolumnmode.displayedcells;

Set datagridview All column widths Auto-adjust

1 this. Dgv_propdemo.autoresizecolumns (datagridviewautosizecolumnsmode.allcells);

Set column width AutoFit for the first column of DataGridView

1 this. Dgv_propdemo.autoresizecolumn (1, datagridviewautosizecolumnmode.displayedcells);

Set DataGridView first line to automatically adjust row height

1 this. Dgv_propdemo.autoresizerow (0, datagridviewautosizerowmode.allcells);

About Performance:

When auto-adjusting with the cells specified by the autoSizeColumnsMode and autoSizeRowsMode properties, if the number of adjustments is excessive then it can result in performance degradation, especially in the case of more rows and columns. Because the underlying API is called for repainting every time the adjustment is made. In this case, using displayedcells instead of Allcells only adjusts the visible cells, which can reduce the adjustments of non-visible cells, thus improving performance.

DataGridView Five: Automatically set column width and row height

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.