Data Grid Columns and OLE DB Adapter

  • Thread starter Thread starter Rich
  • Start date Start date
R

Rich

Code in the sample below (and numerous variations) runs
OK...The query works and successfully binds data to the
grid. But the Column Headers and Widths still look as if
the cde that built the column styles colletion, etc. did
not even run. When I run similar code on a different
platform using SQL Server (and of course the SQL Data
Adapter), everything works fine. In fact, it's a great
way to manipulate amny aspects of grid
formatting....colors, fonts, gridlines, the whole nine
yards.

MSDN documents this quite well but I found nothing that
says it should not work with the OLE DB Adapter, etc.
(I'm using it with Oracle)

Anybody know what's up with this?

Private Sub FillDocGrid(ByVal DocID As Integer)
OleDbSelectCommand2.CommandText=SelectDocsCmd &
DocID.ToString & "'"
DocumentsDA.Fill(TechLibDS, "Documents")

'Tried setting Data Source and Data Member
'both ways...runs the same either way
DocGrid.DataSource = TechLibDS.Tables("Documents")
'DocGrid.DataSource = TechLibDS
'DocGrid.DataMember = "Documents"

Dim DocGridTS As New DataGridTableStyle()
DocGridTS.RowHeadersVisible = False

'Tried setting Mapping Name both ways...
'runs the same either way
DocGridTS.MappingName = "TechLibDDS.Documents"
'DocGridTS.MappingName = "Documents"

Dim IDCS As New DataGridTextBoxColumn()
IDCS.MappingName = "ID"
IDCS.HeaderText = ""
IDCS.Width = 0
DocGridTS.GridColumnStyles.Add(IDCS)

Dim DocDateCS As New DataGridTextBoxColumn()
DocDateCS.MappingName = "DocDate"
DocDateCS.HeaderText = "Date"
DocDateCS.Width = 120
DocGridTS.GridColumnStyles.Add(DocDateCS)

Dim TitleCS As New DataGridTextBoxColumn()
TitleCS.MappingName = "Title"
TitleCS.HeaderText = "Document Title"
TitleCS.Width = 400
DocGridTS.GridColumnStyles.Add(TitleCS)

Dim DescCS As New DataGridTextBoxColumn()
DescCS.MappingName = "Description"
DescCS.HeaderText = "Document Descripition"
DescCS.Width = 800
DocGridTS.GridColumnStyles.Add(DescCS)

DocGrid.TableStyles.Clear()
DocGrid.TableStyles.Add(DocGridTS)
End Sub
 
Hi Richard,

1. I'd recommend setting up table and column styles BEFORE doing the data
binding
2. I'd recommend using the SetDataBinding method instead of assigning the
DataSource and DataMember directly.

Don't ask me why using SetDataBinding is better - it's merely practical
experience and I'd also like to know what is the difference. Probably
someone from Microsoft could explain the details?
 
Back
Top