Click here to Skip to main content
15,889,527 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
how to solve EditItem is not allowed for this datagrid while using add rows
C#
"Datagrid.Items.Add(new DataItem());"

Posted
Updated 11-Oct-19 12:09pm
v2
Comments
Christian Amado 18-Mar-14 13:02pm    
Can you explain more in details?
Namasivayam Raja 19-Mar-14 2:15am    
my problem scenario is
i want use a datagrid for adding a products to the database at the runtime. using this code i add a row in datagrid "Datagrid.Items.Add(new DataItem());".row is added but the exception is raised "EditItem is not allowed for this view"

Hi Namasivayam, may be these links helps you.
Link 1[^]
Link 2[^]
Link 3[^]
Link 4[^]
Link 5[^]

Let me now. Regards
 
Share this answer
 
If you using roweditending or anything related to the corresponding datagrid during reload add like this depending on your names...
System.Windows.Data.CollectionViewSource t_productViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("t_productViewSource")));
t_productViewSource.View.MoveCurrentToFirst();
 
Share this answer
 
**I seen this error in 3 cases**

**case1** : this error shown if double clicking the datagrid then(custom datagrid which contains processed data like analysis)

Simply, Set in Datagrid IsReadOnly="True"

**case2** : this error shown after editing the datagrid, must set during RowEditEnding

(sender as DataGrid).CommitEdit(DataGridEditingUnit.Row);

**case3** : this error shown after RowEditEnding event, then must see where the datagrid is reloading the data, it can happen if viewsource or datagrid is already in use and we try to override the data manually

Let me know if any new cases you seen
 
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