i didn't adapt it to your case but this is working here (drgMain is the
datagrid)
hope it helps
dsForm = New DataSet("data")
dsForm = SqlHelper.ExecuteDataset(gstrCnn, CommandType.Text, strSql)
Dim ts As New DataGridTableStyle
ts.MappingName = "Table"
dgrMain.TableStyles.Clear()
dgrMain.SetDataBinding(dsForm, "Table")
dgrMain.TableStyles.Add(ts)
ts.GridColumnStyles(0).Width = 0
ts.GridColumnStyles(1).Width = 100
ts.GridColumnStyles(2).Width = 50
ts.GridColumnStyles(3).Width = 200
ts.AllowSorting = True
ts.AlternatingBackColor = Color.Lavender
ts.BackColor = Color.WhiteSmoke
ts.ForeColor = Color.MidnightBlue
ts.GridLineColor = Color.Gainsboro
ts.HeaderBackColor = Color.MidnightBlue
ts.HeaderForeColor = Color.WhiteSmoke
ts.LinkColor = Color.Navy
ts.SelectionBackColor = Color.Navy
ts.SelectionForeColor = Color.Lavender
ts.ColumnHeadersVisible = True
"Michael Hesse" <mh****@sbcglobal.net> wrote in message
news:kg*******************@newssvr25.news.prodigy. com...
This must have been covered a lot of times, but I still cannot seem to get
this work. I have a data table called "dt" and a data grid, "dg". The
data table is not part of a data set.
Here is my code. What am I doing wrong?
______________________________________
dg.SetDataBinding(dt, Nothing)
Dim dgts As DataGridTableStyle = New DataGridTableStyle
dgts.MappingName = "dt"
For i As Integer = 1 To 10
Dim CStyle As New DataGridTextBoxColumn
CStyle.Width = i * 100
dgts.GridColumnStyles.Add(CStyle)
Next
dg.TableStyles.Add(dgts)
dg.TableStyles("dt").GridColumnStyles(0).Width = 500
dg.TableStyles("dt").GridColumnStyles(1).Width = 2500
dg.Refresh()
_____________________________________________
Thanks for any help.