Click here to Skip to main content
15,900,725 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi do anyone have an idea about adding new rows to datagridview on clicking add button. provided the DGV is already databound and it contains data and the new empty row to be added should display below the last row.

C#
dgv.DataBindings.Clear();
                dgv.AllowUserToAddRows = true;
                int n = dgv.Rows.Add();
                dgv.Rows[n].Cells["col1;].Value = iaccountID;
                dgv.Rows[n].Cells["col2"].Value = iprojectID;
                dgv.Rows[n].Cells["col3"].Value = DBNull.Value;
                dgv.ClearSelection();
                dgv.CurrentCell = dgv.Rows[n].Cells["col1"];
                dgv.BeginEdit(true);


This is wat I've done so far, by default the AllowUsersToAddRows property is set to false.

When clicking add button I'm setting AllowUsersToAddRow property to true

Thanks in Advance
Posted
Updated 31-Oct-11 19:06pm
v2

1 solution

 
Share this answer
 
Comments
CyborgForever 1-Nov-11 1:08am    
I have already gone through this forum, but it is not exactly what I need.
shijuse 1-Nov-11 1:10am    
pls explain your exact requirement ...
CyborgForever 1-Nov-11 1:23am    
On Load of my page I'm displaying data in DGV by binding the dataset with it. On clicking the ADD button, I'm adding a new row to the DGV,provided few columns of DGV I assign data(as seen in my code,which is invisible in DGV) and few columns with DB.Null. This is what I need

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