How to add multiple rows to datagridview with butten click

Using a bound datagridview.
I need sample code to add multiple rows to a datagridview with butten click event.

I need to add 24 blank rows with one click event.
dave_skyAsked:
Who is Participating?
 
surajgupthaCommented:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
 
For index As Integer = 1 To 24
           MonarhSQL.Tables[0].Rows.Add(MonarhSQL.Tables[0].NewRow())
        Next
        TblJobOrdersDetailDataGridView.DataSource = MonarhSQL.Tables[0].

End Sub
0
 
surajgupthaCommented:
Since you are using a bound datagrid, just add 24 more records to the list or datatable which you are binding to the grid and do a databind again.
0
 
dave_skyAuthor Commented:
I want to do this instantaneously with a button click event. Not one row at a time.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
surajgupthaCommented:
On the Buttom Click you can add all the 24 records so after the button click u would see 24 blank records.
It would appear as if all 24 were inserted. It would appear row by row
0
 
dave_skyAuthor Commented:
I don't really understand what you are trying to explain.

Maybe you can show me some sample code as requested in my opening question.
0
 
surajgupthaCommented:
If you did DataGrid.DataSource = dtTableData;
on Button1_Click()
{
for(int i =0; i < 24; i++)
{
dtTableData.Rows.Add(DtTableData.NewRow());
}
DataGrid.DataSource = dtTableData;
}
0
 
dave_skyAuthor Commented:
I think you may have the solution but I can't convert all the C# code to VB.Net.
0
 
surajgupthaCommented:
For index As Integer = 1 To 24
            dtTable.Rows.Add(dtTable.NewRow())
        Next
        dgrid.DataSource = dtTable
0
 
dave_skyAuthor Commented:
I'm not familiar with your code.
Can you complete this?

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
 
???????????

End Sub

DataGridview: TblJobOrdersDetailDataGridView
Table: TblJobOrdersDetail
DataSet: MonarhSQL
0
 
dave_skyAuthor Commented:
surajguptha,
This works good.

Thank you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.