all groups > vb.net controls > october 2005 >
You're in the

vb.net controls

group:

autowidth for DataGrid with 0 sized columns


autowidth for DataGrid with 0 sized columns Tamas Nyilanszky
10/24/2005 11:40:17 AM
vb.net controls:
Hello,
i have a datagrid which has zero sized columns and i want to write a sub
which automatically resizes the width of all columns so it fits the
overall size of the grid (datagrid.width)

the function i wrote by now is this one:

gridsize:

Public Sub gridsize(ByRef dG As DataGrid, ByRef dS As DataSet)
Dim vcount, k, i, optwidth, dec As Integer

For i = 0 To dS.Tables(0).Columns.Count - 1
If dG.TableStyles.Item(0).GridColumnStyles.Item(i).Width <>
0 Then
vcount += 1
End If
Next

optwidth = CInt(dG.Width / vcount)

For k = 0 To vcount - 1
if dG.TableStyles.Item(0).GridColumnStyles.Item(k).Width =
0 then
dG.TableStyles.Item(0).GridColumnStyles.Item(k).Width = optwidth
end if
Next
End Sub

the problem is, that dS.Tables(0).Columns.Count returns more columns
than dG.TableStyles.Item(0).GridColumnStyles.Item(i) contains -> error.
i dont understand why this happens, the ds is the ds which was passed to
the DG earlier.

maybe there is a function/property for this purpose already made and its
just me being blind, that would be the easiest way

thx in advance
Re: autowidth for DataGrid with 0 sized columns Tamas Nyilanszky
10/24/2005 11:45:43 AM
ah and the 0 sized columns need to stay 0 because they need to be hidden
thats the actual problem.
if you have a more elegant way of solving this problem, id love to hear it.

thx

[quoted text, click to view]
AddThis Social Bookmark Button