相等的gridview列宽 [英] Equal gridview column widths
本文介绍了相等的gridview列宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个gridview,我希望动态设置列.网格从数据表绑定,并且autogeneratecolumns为true.
我试图使用的代码是这个. . .但是似乎没有什么不同:
Hi,
I have a gridview of which I would like the columns to be set dynamically. The grid is bound from a datatable and autogeneratecolumns is true.
The code im attempting to use is this. . .but it doesnt seem to make any difference:
int colWidth = Int16.Parse("150");
if (colWidth > 0)
{
for (int r = 0; r < gvMadeToStock.Rows.Count; r++)
{
for (int i = 0; i < gvMadeToStock.Rows[r].Cells.Count; i++)
{
gvMadeToStock.Rows[r].Cells[i].Width = colWidth;
}
}
}
任何意见,将不胜感激. . .
Any advice would be appreciated. . .
推荐答案
尝试更改列宽而不是单元格宽度,或者尝试设置每个列的AutoSizeMode和FillWeight
try change Column width not cell width or try to set AutoSizeMode and FillWeight of each Column
MyColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
MyColumn.FillWeight = 1/ColumnsCount;
请参阅此
http://msdn.microsoft.com/en-us/library/ms178296.aspx [ ^ ]
http://stackoverflow.com/questions/8265964/asp-net- set-gridview-column-max-width-size [ ^ ]
Refer this
http://msdn.microsoft.com/en-us/library/ms178296.aspx[^]
http://stackoverflow.com/questions/8265964/asp-net-set-gridview-column-max-width-size[^]
这篇关于相等的gridview列宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文