Thanks Ken,
I had already seen this site, which is very useful, However I downloaded the
VB but could not get it to work with my DataGrid.
It determines the number of columns with:
dataTable1 = CType(Me.dataGrid1.DataSource, DataTable)
numCols = dataTable1.Columns.Count
I get an unhandled exception on the first line, of type
'System.InvalidCastException'
'Specified 'ast is not valid'
My DataGrid is based on DataViews (with filter and sort) not directly on a
DataTable.
So I guess, I am really trying to determine the number of columns in the
particular DataView.
Problem is that the DataView doesn't have a columns property.
Also in that example, it used
scrollBarWidth = IIf(Me.dataGrid1.VerticalScrollBarVisible,
SystemInformation.VerticalScrollBarWidth, 0)
To return the width of the Vertical ScrollBar. I could not get a
VerticalScrollBar property so used your code.
Doug
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:OH**************@TK2MSFTNGP14.phx.gbl...
Hi,
http://www.syncfusion.com/FAQ/WinFor...c44c.asp#q871q
Ken
-------------------------
"Doug Bell" <dug@bigpond> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi,
How can I determine the number of columns in a DataGrid?
What I am trying to do is to build a function that will resize the last
column to fill the remaining space in the DataGrid.
Something like:?
Dim intCols As Integer = DataGrid1.DataSource.Columns.Count
Dim intUsedWidth as Integer=0
Dim i as Integer = 0
Dim intTargetWidth as Integer = DataGrid1.Width
For Each ctrl AS Control In Me.DataGrid1
If TypeOf ctrl Is VScrollBar then
If ctrl.Visible then
intTargetWidth =intTargetWidth - ctrl.Width
EndIf
EndIf
Next
Do While i< intCols
intUsedWidth=intUsedWidth +
DataGrid1.TableStyles(st).GridColumnStyles(i).Widt h
i=i+1
loop
If intUsedWidth<intTargetWidth then
DataGrid1.TableStyles(st).GridColumnStyles(i).Widt h=intTargetWidth -
intUsedWidth
endif
Thanks
Doug