G
Guest
I am binding a datatable to a datagrid. I can’t seem to find the right code
to control the column width. I searched the web and found this code:
Dim ColumnCount As Integer
ColumnCount = dtgAny.VisibleColumnCount()
Dim i As Short
Try
With dtgAny
Dim myTableStyle As DataGridTableStyle = New
DataGridTableStyle
.TableStyles.Add(myTableStyle)
For i = 0 To ColumnCount
dtgAny.TableStyles(0).GridColumnStyles(i).Width = 1000
Next
.TableStyles(0).DataGrid.Refresh()
.Refresh()
End With
When I run this, I get the message:
Index was out of range. Must be non-negative and less than the size of the
collection. Parameter name: index
when i = 1
There is no effect on the grid.
Please help.
to control the column width. I searched the web and found this code:
Dim ColumnCount As Integer
ColumnCount = dtgAny.VisibleColumnCount()
Dim i As Short
Try
With dtgAny
Dim myTableStyle As DataGridTableStyle = New
DataGridTableStyle
.TableStyles.Add(myTableStyle)
For i = 0 To ColumnCount
dtgAny.TableStyles(0).GridColumnStyles(i).Width = 1000
Next
.TableStyles(0).DataGrid.Refresh()
.Refresh()
End With
When I run this, I get the message:
Index was out of range. Must be non-negative and less than the size of the
collection. Parameter name: index
when i = 1
There is no effect on the grid.
Please help.