SETHA SITE INFORMATION

  • Increase font size
  • Default font size
  • Decrease font size

Getting Start with DataGridView Control in Visual Basic 2008

E-mail Print PDF

This article enclosed with video clip shows you to get start using the DataGridView Control in Visual Basic .Net.

  • Add Columns to DataGridView
  • Define Column Width
  • Add Data to DataGridView

'add column
With Me.DataGridView1
   .Columns.Add("id", "ID")
   .Columns.Add("name", "Name")
   .Columns.Add("sex", "Sex")
End With

'define columns width
With Me.DataGridView1
   .Columns("id").Width = 200
   .Columns("name").Width = 500
   .Columns("sex").Width = 100
End With

'add data (10 rows)
For i As Integer = 1 To 10
    Me.DataGridView1.Rows.Add()
    With Me.DataGridView1.Rows(Me.DataGridView1.Rows.Count - 2)
        .Cells("id").Value = i
        .Cells("name").Value = "Name " & i
        .Cells("sex").Value = "M"
    End With
Next