DataGridTableStyle

G

Guest

I am using the following code to format a DataGrid:

aGridTableStyle.MappingName = "schedule"
With acol1
.MappingName = "Week"
.HeaderText = "Week"
.Width = 25
.Alignment = HorizontalAlignment.Left
.TextBox.Enabled = False
End With
With acol2
.MappingName = "Away"
.HeaderText = "Away"
.Width = 70
.Alignment = HorizontalAlignment.Left
.TextBox.Enabled = False
End With
With acol3
.MappingName = "Home"
.HeaderText = "Home"
.Width = 70
.Alignment = HorizontalAlignment.Left
.TextBox.Enabled = False
End With

With aGridTableStyle.GridColumnStyles
.Add(acol1)
.Add(acol2)
.Add(acol3)
End With

DataGrid1.TableStyles.Add(aGridTableStyle)

DataGrid1.DataSource = ds.Tables("Schedule")
DataGrid1.Expand(-1)
DataGrid1.NavigateTo(0, "schedule")

When I run my program, the datagrid displays week, away, and home twice (week away home week away home). Help!
 
E

Earl

Set the Datagrid.Datasource property BEFORE setting up your tablesyles. Then
use the following syntax to setup your tablestyle routine (I keep those
routines separate so I can focus on just formatting the tablestyles). And
unless you have a parent-child relationship, you do not need NavigateTo or
Expand methods.

Private Sub AdjustTableStyle()

Dim tblStyle As New DataGridTableStyle
'this must match up with the actual datasource table that was bound
tblStyle.MappingName = "schedule"
DataGrid1.TableStyles.Clear()
DataGrid1.TableStyles.Add(tblStyle)
...................
...................

Tom Nowak said:
I am using the following code to format a DataGrid:

aGridTableStyle.MappingName = "schedule"
With acol1
.MappingName = "Week"
.HeaderText = "Week"
.Width = 25
.Alignment = HorizontalAlignment.Left
.TextBox.Enabled = False
End With
With acol2
.MappingName = "Away"
.HeaderText = "Away"
.Width = 70
.Alignment = HorizontalAlignment.Left
.TextBox.Enabled = False
End With
With acol3
.MappingName = "Home"
.HeaderText = "Home"
.Width = 70
.Alignment = HorizontalAlignment.Left
.TextBox.Enabled = False
End With

With aGridTableStyle.GridColumnStyles
.Add(acol1)
.Add(acol2)
.Add(acol3)
End With

DataGrid1.TableStyles.Add(aGridTableStyle)

DataGrid1.DataSource = ds.Tables("Schedule")
DataGrid1.Expand(-1)
DataGrid1.NavigateTo(0, "schedule")

When I run my program, the datagrid displays week, away, and home twice
(week away home week away home). Help!
 

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