自动适应列宽 http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q877q 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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 } 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 } 关于datatable绑定到gridview上的后续操作 一个关于模拟表单提交的郁闷问题? 保存图片时出错GDI+一般性 一个加密与解密的问题! DataList控件模板中的FileUpLoad控件取值问题!!!在线等!急。急。急!!! 请问.Net开源项目中有没有比较好的基于C/S的“表示层框架” 用vs2008 如何实现word2007文档中的字符串替换 C# for循环求助 服务器端程序单实例的问题?都进来看看,可能大家都会遇到这样的问题 c#中怎样打开指定的excel文件? 正则表达式:如何匹配用逗号分隔的4个浮点数? 在C#中如何调用WINDOWS API
{
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
}
{
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
}