70分: http://community.csdn.net/Expert/topic/4092/4092426.xml?temp=.2082941
26分: http://community.csdn.net/Expert/topic/4091/4091493.xml?temp=.1310388LaoDai_Net(『老代.Net』) 您的代码我试了, 没效果, 单元格是等长的.
26分: http://community.csdn.net/Expert/topic/4091/4091493.xml?temp=.1310388LaoDai_Net(『老代.Net』) 您的代码我试了, 没效果, 单元格是等长的.
请问最后一句 dataGrid1.TableStyles["customers"] 中的 customers 是表名吗
是怎么设置的.
dataGrid1要绑定的是dastset 还是dataview
public void AutoSizeCol(int col) // 参数是索引号对吗
{
float width = 0;
int numRows = ((DataTable) dataGrid1.DataSource).Rows.Count;
Graphics g = Graphics.FromHwnd(dataGrid1.Handle);
StringFormat sf = new StringFormat(StringFormat.GenericTypographic);
SizeF size; for(int i = 0; i < numRows; ++ i)
{
size = g.MeasureString(dataGrid1[i, col].ToString(), dataGrid1.Font, 500, sf);
if(size.Width > width)
width = size.Width;
} g.Dispose(); dataGrid1.TableStyles["customers"].GridColumnStyles[col].Width = (int) width + 8; // 8 is for leading and trailing padding
}
我循环调用数据表的列, 每列都调用一次自动调整, 可就是没效果.我怀疑是 dataGrid1.TableStyles["customers"]. 有问题, 或是 dataGrid1 数据绑定有问题(数据集还是数据视图) 所以在发帖子问问, 有人能回答我吗