Adding rows to DataGrid

  • Thread starter Thread starter David Sawyer
  • Start date Start date
D

David Sawyer

When I try and use DataGrid I cannot find any command to
add rows or pre-set a number of rows. I would like to
build a table of 34 rows and 5 colums.
 
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim row As DataRow
Dim colIdx, rowIdx As Integer

'Bind
dg.DataSource = tab
For colIdx = 1 To 5
tab.Columns.Add(CType(colIdx, String))
Next
For rowIdx = 1 To 35
row = tab.NewRow()
row("1") = CType(rowIdx, String)
tab.Rows.Add(row)
Next




End Sub
 
Put the tab declaration as a form class member

Public Class Form1
Inherits System.Windows.Forms.Form
Dim tab As New DataTable("MyTable") ' <<<<<<<<<<<<<<<<<<<
 
Back
Top