1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
' Please be sure of the database path, I suppose it will be in the same folder where the application exe file is in (usually should be in 'YourProjectPath\bin\debug')
Dim MyConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Application.StartupPath + "\Customers.mdb" ' Chemin ou se trouve la base de donnee ici dans \bin\debug là où il y a le fichier exe
' Génération de l'objet DataSet et le DataAdapter
Dim ds As New DataSet()
' All 'Customers' table's columns could fit in one page
Dim da As OleDbDataAdapter = New OleDbDataAdapter("SELECT * FROM Customers", MyConnectionString)
' All 'Customers2' table's columns could fit in two page
'Dim da As New OleDbDataAdapter("SELECT * FROM Customers2", MyConnectionString)
Try
da.Fill(ds, "dt")
Catch ex As Exception
MessageBox.Show("Operation failed: " + ex.ToString(), Application.ProductName + " - Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
Return
End Try
' Réglage du style du contrôle DataGridView
myDataGridView.ColumnHeadersDefaultCellStyle.Font = New Font("Tahoma", 9, FontStyle.Bold, GraphicsUnit.Point)
myDataGridView.ColumnHeadersDefaultCellStyle.BackColor = SystemColors.ControlDark
myDataGridView.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.[Single]
myDataGridView.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
myDataGridView.DefaultCellStyle.Font = New Font("Tahoma", 8, FontStyle.Regular, GraphicsUnit.Point)
myDataGridView.DefaultCellStyle.BackColor = Color.Empty
myDataGridView.AlternatingRowsDefaultCellStyle.BackColor = SystemColors.ControlLight
myDataGridView.CellBorderStyle = DataGridViewCellBorderStyle.[Single]
myDataGridView.GridColor = SystemColors.ControlDarkDark
' DataGridViewControl la reliure au DataSet généré ci-dessus
myDataGridView.DataSource = ds
myDataGridView.DataMember = "dt"
' Modification de la dernière colonne de l'alignement dans le droit alignement
myDataGridView.Columns(myDataGridView.Columns.Count - 1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
' Réglage de chaque colonne pour être en forme que le contenu de l'ensemble de ses cellules, y compris l'en-tête de cellules
myDataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells)
'MyDataGridView.Columns[0].Visible = false; |
Partager