开发者

Adjusting datagrid columns in a C# Windows application

How can 开发者_运维知识库I adjust the column widths based on a datagrid's displayed values in a C# Windows application?


You can do this by using MeasureString to compute the size of the text in each cell, and then take the maximum value.

You can find the code snippet to do this here - http://www.syncfusion.com/FAQ/windowsforms/faq_c44c.aspx#q877q


If you are using DataGridView as your datagrid control there's an AutoSizeColumns property that if set to true it will adjust columns widths automatically.


Well one approach is to set the attribute AutoSizeColumnsMode to "Fill" which will resize the columns dynamically in order to fill the extent of the grid. Then, for each column you can also specify the FillWeight (in "Edit Columns") in order to have a "weighted" resizing of the columns.

Otherwise you can set the default width for each column by setting the "Width" attribute in "Edit Columns"

If you want to do this programmatically at runtime, you can do it by calling

dataGridView1.Columns[...].Width = XX
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜