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
| Public Class Form1
Private dgresult As New DataGridView
Private Sub init()
dgresult.Columns.Add("col1", "col1")
dgresult.Columns.Add("col2", "col2")
dgresult.Columns.Add("col3", "col3")
dgresult.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.ColumnHeader
dgresult.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllHeaders
dgresult.ReadOnly = True
dgresult.Font = New Font("arial", 9, FontStyle.Bold)
dgresult.EnableHeadersVisualStyles = False
dgresult.ColumnHeadersDefaultCellStyle.BackColor = Color.PowderBlue
dgresult.AutoSize = True
dgresult.Location = New Point(17, 10)
Me.Controls.Add(dgresult)
End Sub
Private Sub insertmethod1()
'il y a une rangée crée
dgresult.Rows(0).Cells("col1").Value = "x1"
dgresult.Rows(0).Cells("col2").Value = "y1"
dgresult.Rows(0).Cells("col3").Value = "z1"
' ajoute une nouvelle rangée
dgresult.Rows.Add()
dgresult.Rows(1).Cells("col1").Value = "x2"
dgresult.Rows(1).Cells("col2").Value = "y2"
dgresult.Rows(1).Cells("col3").Value = "z2"
End Sub
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
init()
insertmethod1()
End Sub
End Class |