Re-Arrange columns in datagrid?

W

What-a-Tool

Ended up using the following to hide unwanted columns and set the width of a
column. Now I want to re-arrange the displayed order of the columns, so I
tried creating another table style and adding the columns in the order I
wanted them, but for some reason I end up with all table style settings
gone. Anyone see what I'm doing wrong?
Thanks - Sean

'Hide un-wanted column
Me.DsGameInfo.Tables("Games").Columns("Home").ColumnMapping =
MappingType.Hidden

'Set column widths

Dim dgts As New DataGridTableStyle()

dgts.MappingName = "Games"

Me.dgGames.TableStyles.Add(dgts)

dgts.GridColumnStyles("Game").Width = 150

'Re-arrange colums

Dim dgts2 As New DataGridTableStyle()

dgts2.GridColumnStyles.Add(dgts.GridColumnStyles("Game"))

dgts2.GridColumnStyles.Add(dgts.GridColumnStyles("Home Score"))

dgts2.GridColumnStyles.Add(dgts.GridColumnStyles("Guest Score"))

dgts2.GridColumnStyles.Add(dgts.GridColumnStyles("Week / Year"))

Me.dgGames.TableStyles.Remove(dgts)

Me.dgGames.TableStyles.Add(dgts2)

Me.dgGames.Refresh()
 
W

What-a-Tool

Stupid mistake - forgot the:
dgts2.MappingName = "Games"
Re-arranges my columns in the desired order now.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top