Click here to Skip to main content
15,567,415 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound.Please Help me
C#
List<purchaseentity> entityList = facade.GetPurchase(Convert.ToString(TxtPurNo.Text.Trim()));
                                                                   
                        if (entityList != null)
                        {
                           
                              
                           foreach (PurchaseEntity  pntity in entityList)
                            {
     dgvPrd1.Rows.Add(new object[] { string.Format("0:0.00}",pntity.ProductId),pntity.PRoductName,pntity.Packing,pntity.BatchNo,pntity.PurPrice,pntity.Qty,pntity.Free,pntity.Margin});
                            }
                        }
              catch
            {
            }
Posted
Updated 2-May-13 23:48pm
v6
Comments
Sergey Alexandrovich Kryukov 1-May-13 0:07am    
Not a question. Help with what? Why do you think you need to add a row to a data-bound grid view? what to do with that row?
—SA
Amarender1479 1-May-13 0:14am    
i show the records from database into datagrid based on Id....when i bind the records the abow error is came......
[no name] 1-May-13 8:17am    
The error means exactly what is says. You are trying to add a new row to a databound grid. Either remove the binding or add the object to your database and re-query the data.
Amarender1479 1-May-13 8:21am    
am adding the new row..into datagrid
[no name] 1-May-13 8:36am    
Which part of "you cant do that" is it that you do not understand?

1 solution

Dont you just need to add a new object to the DataGrid DataSource

Person Bob = new Person();
//Assumption PersonList is DataSource to DataGrid
PersonsList.Add(Bob);
 
Share this answer
 

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