One more row in DataGrid after Binding ItemSource?

Mar 10, 2009 at 9:22 AM
Hi, there always are one more row in my DataGrid with no value after I bind the ItemSource. My collection has 5 items indeed. However it shows 6 Rows. The last row is totally no use and no value.

I found the Items value in datagrid show SourceCollection .Count = 5, but Item.Count = 6? I don't know why. Does anybody hit it before and can give me the answer and solution.

I manually add the collection one by one using myDataGrid.Add(item), it's OK with 5 rows. But when I edit one column, it reported error message that 'EditItem' is not allowed for this view. Though it's no problem when I bind ItemSource .

Thank you in advance,
Mar 11, 2009 at 2:19 AM
This additional row is the new blank row which is used to add additional rows.  By default this is turned on.  To turn it off set DataGrid.CanUserAddRows = false. 

The reason why it doesn't show up when you initialize the DataGrid via DataGrid.Items.Add() is because when initializing with unbound data you will not get the add new row functionality.  Also, the error message you are getting is b/c editing functionality is not supported with unbound data.
Mar 11, 2009 at 2:38 AM
Thanks very much.
Yes, you're quite right. The problem is solved.