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
| Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
EnableDoubleBuffered(DataGridViewMain)
DataGridViewMain.Columns.Add(col0) : DataGridViewMain.Columns.Add(col1) : DataGridViewMain.Columns.Add(col2) : DataGridViewMain.Columns.Add(col3)
Lecture_DataBase()
Affichage_DataGrid()
End Sub
Public Sub EnableDoubleBuffered(ByVal dgv As DataGridView)
Dim dgvType As Type = dgv.[GetType]()
Dim pi As PropertyInfo = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance Or BindingFlags.NonPublic)
pi.SetValue(dgv, True, Nothing)
End Sub
Sub Affichage_DataGrid()
With AA_Main.col0 : .DataPropertyName = "path" : .HeaderText = "Path" : .Name = "path" : .Width = 75 : .Visible = True : .SortMode = DataGridViewColumnSortMode.NotSortable : End With
With AA_Main.col1 : .DataPropertyName = "type" : .HeaderText = "type" : .Name = "type" : .Width = 20 : .Visible = True : .SortMode = DataGridViewColumnSortMode.NotSortable : End With
With AA_Main.col2 : .DataPropertyName = "description" : .HeaderText = "Description" : .Name = "Description" : .Width = 250 : .Visible = True : .SortMode = DataGridViewColumnSortMode.NotSortable : End With
With AA_Main.col3 : .DataPropertyName = "fournisseur" : .HeaderText = "Fournisseur" : .Name = "Fournisseur" : .Width = 100 : .Visible = True : .SortMode = DataGridViewColumnSortMode.NotSortable : End With
DataGridViewMain.AutoGenerateColumns = False
DataGridViewMain.DataSource = Produit
End Sub
Private Sub DataGridViewMain_RowPostPaint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles DataGridViewMain.RowPostPaint
If Produit.Rows.Count - 1 = 0 Then Exit Sub
If e.RowIndex = -1 Then Exit Sub
Debug.Print("RowPostPaint : " & e.RowIndex)
If Produit.Rows(e.RowIndex).Item("type") = 0 Then
DataGridViewMain.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.FromArgb(235, 220, 110)
'' DataGridViewMain.Rows(e.RowIndex).Cells("col0").Value = My.Resources.img1 (N°1)
End If
End Sub |
Partager