try something like this:
public Sub AddCustomDataTableStyle()
' adds 2 collumns to datagrid
datagrid1.SetDataBinding(myDataset,myDataset.Tables(0).TableName)
Dim ts1 As New DataGridTableStyle()
ts1.MappingName = myDataset.Tables(0).TableName
ts1.AlternatingBackColor = Color.LightGoldenrodYellow
Dim dCol1 As New DataGridTextBoxColumn()
dCol1.MappingName = "UtilCod" 'name of collumn
dCol1.HeaderText = "Code"
dCol1.Width = 150
ts1.GridColumnStyles.Add(dCol1)
Dim dCol2 As New DataGridTextBoxColumn()
dCol2.MappingName = "UtilDsc" 'name of collumn
dCol2.HeaderText = "Description"
dCol2.Width = 250
ts1.GridColumnStyles.Add(dCol2)
datagrid1.TableStyles.Add(ts1)
end sub
Ana
> Hello:
I finally assigned the TableStyles to the datagrid. Now when I run the
program, I get the following error:
"The data grid column styles collection already contains a column style
with
the same mapping name."
If I put dgCustOrders.TableStyles.Clear() first, I don't get this error,
but
I don't get any styles either.
How to fix this?
I would appreciate any suggestions.
Thank you,
--
Peter Afonin