DataGrid Problem

Rat

Well-known member
Joined
Aug 2, 2005
Messages
72
Location
Somewhere between 0 and 1
Programming Experience
1-3
I've attached the following file, the data loads in from the database, but i have a problem .. it doesn't immediately show the columns and it's contents, i have to click a "+" and the Table name to get there ... how do i fix this ?

I want to make it directly go to show the columns and contents.

Here's the code ...


VB.NET:
Private Sub frmDBExplorer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  
Try 
 
Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\DB\DB.mdb"
 
Dim myConnection As OleDbConnection = New OleDbConnection
 
myConnection.ConnectionString = connString
 
Dim DataAdapter As OleDbDataAdapter = New OleDbDataAdapter("Select * from XML", myConnection)
 
Dim DataSet As DataSet = New DataSet
 
DataAdapter.Fill(DataSet, "XML")
 
dgBrowse.DataSource = DataSet.DefaultViewManager
 
Catch ex As Exception
 
MsgBox(ex.Message + ex.Source, MsgBoxStyle.Critical + MsgBoxStyle.OKOnly, "Exception Message")
 
End Try
 
End Sub
 
Since you are not looking for a custom view of your dataset, dont set the DataSource for your Datagrid to use a DefaultViewManager. Instead, set your DataSource to the specific table name you wish to display.

In your case:

dgBrowse.DataSource = DataSet.Tables("XML")

BTW, I wouldnt name your objects by the their type. Like 'Dim DataSet as DataSet'. You should give it some kind of unique name. Like maybe 'Dim ds as Dataset'. Just a thought.

HTH

Blokz
 
Back
Top