Format 2 DataGrids differently with same datasource?

T

tomb

This is making me crazy!
vb.net 2003
I have two datagrids, datasource is the same datatable. I need the
first one to show only 2 columns, the second to show 99 columns.
They also have to be in sync - if I resort one, the other must also
resort. That's why I am not using dataviews. But this doesn't work.
The second grid shows 99 columns, the first shows all 108. What gives?

Please help?!?!

Here is my table styles code.

Public Function connectWhatif(ByRef grd As Windows.Forms.DataGrid, ByRef
grdB As Windows.Forms.DataGrid) As Boolean

Dim i As Integer
Dim tStyle As Windows.Forms.DataGridTableStyle
Dim bCol As Windows.Forms.DataGridBoolColumn
Dim tCol As Windows.Forms.DataGridTextBoxColumn

Dim tStyleB As Windows.Forms.DataGridTableStyle
Dim bColB As Windows.Forms.DataGridBoolColumn
Dim tColB As Windows.Forms.DataGridTextBoxColumn

grdB.DataSource = dtWhatif
grd.DataSource = dtWhatif

tStyleB = New Windows.Forms.DataGridTableStyle
tStyleB.MappingName = "whatifB"

tColB = New Windows.Forms.DataGridTextBoxColumn
tColB.Width = 0
tColB.NullText = ""
tColB.HeaderText = ""
tColB.MappingName = "rowid"
tColB.ReadOnly = True
tStyleB.GridColumnStyles.Add(tColB)

tColB = New Windows.Forms.DataGridTextBoxColumn
tColB.Width = 90
tColB.NullText = ""
tColB.HeaderText = "Contract"
tColB.MappingName = "contract"
tColB.ReadOnly = True
tStyleB.GridColumnStyles.Add(tColB)

tColB = New Windows.Forms.DataGridTextBoxColumn
tColB.Width = 75
tColB.NullText = ""
tColB.HeaderText = "Position"
tColB.TextBox.TextAlign = HorizontalAlignment.Right
tColB.MappingName = "current"
tColB.ReadOnly = True
tStyleB.GridColumnStyles.Add(tColB)

grdB.TableStyles.Add(tStyleB)
grdB.Width = 165


tStyle = New Windows.Forms.DataGridTableStyle
tStyle.MappingName = "whatif"

For i = 1 To 99
tCol = New Windows.Forms.DataGridTextBoxColumn
tCol.Width = 75
tCol.NullText = ""
tCol.HeaderText = "Pos " & Trim(Str(i))
tCol.MappingName = "pos" & Trim(Str(i))
tCol.TextBox.TextAlign = HorizontalAlignment.Right
tCol.ReadOnly = False
tStyle.GridColumnStyles.Add(tCol)
Next

grd.TableStyles.Add(tStyle)

grd.Width = 7500


Return True

Thanks,
Tom
 
T

tomb

I found the flaw, FINALLY! It was my mapping name for grdB. That's
what I get for copying and pasting!

T
 
Top