Hi !
First of all, I apologize for my poor english...
I've a cast problem with the code you can find below.
I really don't understand why ?
I'm trying to make a very simple WindowsForm application wich works with the
customers table of the northwind database.
You can find the database hear :
http://www.microsoft.com/downloads/details.aspx?FamilyID=C6661372-8DBE-422B-8676-C632D66C529C&displaylang=EN
There is no problem if you remove this line of code :
Me._dg.TableStyles.AddRange(New System.Windows.Forms.DataGridTableStyle()
{Me._ts})
I just want to populate my DataGrid with the CustomerID (and later the
CompanyName) and using styles seems to be a good way to do this ?
Can every one help me to find what's the problem with my code...?
Any help would be appreciated.
Hervé
**** code ****
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Namespace DefaultNamespace
Public Class MainForm
Inherits System.Windows.Forms.Form
Private _cnx As System.Data.OleDb.OleDbConnection
Private _tbcID As System.Windows.Forms.DataGridTextBoxColumn
Private _ds As System.Data.DataSet
Private _cmdSelect As System.Data.OleDb.OleDbCommand
Private _ts As System.Windows.Forms.DataGridTableStyle
Private _dg As System.Windows.Forms.DataGrid
Private _da As System.Data.OleDb.OleDbDataAdapter
Public Shared Sub Main
Dim fMainForm As New MainForm
fMainForm.ShowDialog()
End Sub
Public Sub New()
MyBase.New
'
' The Me.InitializeComponent call is required for Windows Forms designer
support.
'
Me.InitializeComponent
'
' TODO : Add constructor code after InitializeComponents
'
Me._da.Fill(Me._ds, "Customers" )
End Sub
#Region " Windows Forms Designer generated code "
' This method is required for Windows Forms designer support.
' Do not change the method contents inside the source code editor. The
Forms designer might
' not be able to load this method if it was changed manually.
Private Sub InitializeComponent()
Me._da = New System.Data.OleDb.OleDbDataAdapter
Me._dg = New System.Windows.Forms.DataGrid
Me._ts = New System.Windows.Forms.DataGridTableStyle
Me._cmdSelect = New System.Data.OleDb.OleDbCommand
Me._ds = New System.Data.DataSet
Me._tbcID = New System.Windows.Forms.DataGridTextBoxColumn
Me._cnx = New System.Data.OleDb.OleDbConnection
CType(Me._dg,System.ComponentModel.ISupportInitialize).BeginInit
CType(Me._ds,System.ComponentModel.ISupportInitialize).BeginInit
Me.SuspendLayout
'
'_da
'
Me._da.SelectCommand = Me._cmdSelect
'
'_dg
'
Me._dg.CaptionVisible = false
Me._dg.DataMember = ""
Me._dg.DataSource = Me._ds
Me._dg.Dock = System.Windows.Forms.DockStyle.Left
Me._dg.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me._dg.Location = New System.Drawing.Point(0, 0)
Me._dg.Name = "_dg"
Me._dg.ReadOnly = true
Me._dg.Size = New System.Drawing.Size(204, 418)
Me._dg.TabIndex = 0
Me._dg.TableStyles.AddRange(New System.Windows.Forms.DataGridTableStyle()
{Me._ts})
'
'_ts
'
Me._ts.DataGrid = Me._dg
Me._ts.GridColumnStyles.AddRange(New
System.Windows.Forms.DataGridColumnStyle() {Me._tbcID})
Me._ts.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me._ts.MappingName = "Customers"
Me._ts.ReadOnly = true
'
'_cmdSelect
'
Me._cmdSelect.CommandText = "select * from Customers"
Me._cmdSelect.Connection = Me._cnx
'
'_ds
'
Me._ds.DataSetName = "Customers"
Me._ds.Locale = New System.Globalization.CultureInfo("fr-FR")
'
'_tbcID
'
Me._tbcID.HeaderText = "ID"
Me._tbcID.MappingName = "CustomerID"
Me._tbcID.NullText = " "
Me._tbcID.ReadOnly = true
Me._tbcID.Width = 80
'
'_cnx
'
Me._cnx.ConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;Password="""";Data
Source=E:\Projets\Customers\bas"& _
"e\Nwind.mdb;Persist Security Info=True"
'
'MainForm
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(564, 418)
Me.Controls.Add(Me._dg)
Me.Name = "MainForm"
Me.Text = "MainForm"
CType(Me._dg,System.ComponentModel.ISupportInitialize).EndInit
CType(Me._ds,System.ComponentModel.ISupportInitialize).EndInit
Me.ResumeLayout(false)
End Sub
#End Region
End Class
End Namespace