本文介绍了DataGridView - 如何设置列宽?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有 DataGridView
控件的 WinForms 应用程序.我的控件有五个列(比如姓名"、地址"、电话"等)
I have a WinForms application with DataGridView
control. My control has fivecolumns (say "Name", "Address", "Phone" etc)
我对默认的列宽不满意.我想对列的外观有更多的控制.我想要的是是能够执行以下操作之一:
I am not happy with default column width. I want to have more control over column appearance. What I wantis to be able to do one of the following:
- 以百分比为单位设置每列的宽度
- 以像素为单位设置每列的宽度
- 使用其他一些最佳实践方法(使宽度适合文本等)
请建议 - 使用哪个属性以及如何使用.
Please suggest - which property to use and how.
推荐答案
您可以使用 DataGridViewColumn.Width 属性来实现:
You can use the DataGridViewColumn.Width property to do it:
DataGridViewColumn column = dataGridView.Columns[0];
column.Width = 60;
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcolumn.width.aspx
这篇关于DataGridView - 如何设置列宽?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!