> Public Sub AutoSizeCol(ByRef dg As DataGrid, _ > Optional ByVal col As Integer = 0, _ > Optional ByVal iTable As Integer = 0) > > Dim swidth As Single = 0 > Dim iPadding As Int16 = 8 ' Set the padding size > > Dim g As Graphics = Graphics.FromHwnd(dg.Handle) ' Get a handle to the grid > Dim sf As StringFormat = New StringFormat(StringFormat.GenericTypographic) ' We need this for the measurements > Dim size As SizeF ' Stores an ordered pair of floating-point numbers > > Try > Dim i As Integer > For i = 0 To 5000000 ' Loop till EOF then fall out to finally > size = g.MeasureString(dg(i, col).ToString(), dg.Font, 500, sf) ' Get the 'size' of the text > If size.Width > swidth Then ' If this is the biggest save it > swidth = size.Width ' Keep collecting the largest size > End If > Next > Catch ' Just run like -while not EOF- > Finally ' Finally :) > g.Dispose() ' House cleaning > dg.TableStyles(iTable).GridColumnStyles(col).Width = swidth + iPadding ' Padding > End Try > End Sub > >>