• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 235
  • Last Modified:

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.
0
dave_sky
Asked:
dave_sky
  • 5
  • 5
1 Solution
 
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
 
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
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 
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
 
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
 
dave_skyAuthor Commented:
surajguptha,
This works good.

Thank you.
0

Featured Post

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.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now