dataGrid1.Handle(Handle 不是System.Web.UI.WebControls.DataGrid成员

wisdom1 2011-05-06 05:20:46

如题

我用下列代码 提示: 自动调整宽度


Public Sub AutoSizeCol(ByVal col As Integer, ByVal dataGrid1 As DataGrid)
Dim width As Single
width = 0
Dim numRows As Integer
numRows = CType(dataGrid1.DataSource, DataTable).Rows.Count
Dim g As Graphics
Dim Handle As System.IntPtr
g = Graphics.FromHwnd(dataGrid1.Handle)
Dim sf As StringFormat
sf = New StringFormat(StringFormat.GenericTypographic)
Dim size As SizeF
Dim i As Integer
i = 0

Do While (i < numRows)
size = g.MeasureString(dataGrid1(i, col).ToString, dataGrid1.Font, 500, sf)
If (size.Width > width) Then
width = size.Width
End If
i = (i + 1)
Loop

g.Dispose()
dataGrid1.TableStyles("customers").GridColumnStyles(col).Width = CType(width, Integer)

End Sub
...全文
38 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
wisdom1 2011-05-06
  • 打赏
  • 举报
回复
g = Graphics.FromHwnd(dataGrid1.Handle)

提示 Handle 不是System.Web.UI.WebControls.DataGrid成员?

请问是什么原因呢
wisdom1 2011-05-06
  • 打赏
  • 举报
回复
提示 Handle 不是System.Web.UI.WebControls.DataGrid成员?

请指点 谢谢

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧