Search code examples
vb.netvisual-studiodatagridviewrow

How to add Row to DataGridView in Visual Basic (Visual Studio)


I want to be able to add a new row to my already existing DataGridView through the use of a button. How do I add this? (Using Visual Basic on Visual Studio)

Here is the Code Filling the DataGridView.

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    Dim connection As New SqlConnection(PlaceHolder for String)
    Dim Table As New DataTable()
    
    Dim Adapter As New SqlDataAdapter("SELECT * FROM TrackMain$", connection)
   
    Adapter.Fill(Table)
    
    DataGridView1.DataSource = Table
    bind_data()

End Sub

Solution

  • bind_data() method seems to come from this reference.

    If you want to add a new empty row, just edit it directly on DataGridView. For example: enter image description here

    To add a new row with data, you can use DataTable:

    dt.Rows.Add(...)