Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
csvData is a DataTable bound to a DataGridView. Compiles & runs no errors . . but after refresh, no new row appears in grid . . . ?? Is there something missing?


private void addNewRowButton_Click(object sender, EventArgs e)
{
csvData.NewRow();
DataGridView1.Refresh();

}

The sender of the addNewRowButton is the Form1 . . . a WINDOWS form.
Posted
Updated 13-Jan-14 6:03am
v4
Comments
Richard C Bishop 13-Jan-14 11:39am    
Is this Windows or web forms?

Perhaps it would help is you added the new row to the table?
DataTable.NewRow[^] just creates a new blank row with the correct schema / columns...
 
Share this answer
 
Comments
JOHNNYDEMICHAEL 13-Jan-14 12:13pm    
Doesn't the above add a new row to the table? I want a blank row to appear in the DataGridView for the user to enter data. Shouldn't the blank row appear in the grid?
OriginalGriff 13-Jan-14 12:18pm    
No - if you look at the link, it describes what it does: creates a new blank row, it doesn't try to add it to the DataTable.Rows collection - you have to do that manually afterwards (so that any target data source doesn't get updated with "empty" data accidentally).
JOHNNYDEMICHAEL 13-Jan-14 17:09pm    
I understand . . . thanks!
OriginalGriff 13-Jan-14 17:40pm    
You're welcome!
You need to bind the DGV again like below.
C#
private void addNewRowButton_Click(object sender, EventArgs e)
{
    csvData.NewRow();
    // Provide Column values for the New Row.

    DataGridView1.DataSource = csvData;
    DataGridView1.DataBind();
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900