Missing empty row placeholder in DataGrid

Jan 12, 2009 at 7:36 PM

When I first started playing around with the WPF DataGrid, it displayed an empty line at the bottom, where a new item could be added to the bound collection.

But at some point it disappeared.

Beyond setting CanUserAddRows to true (which didn't have any visible effect) I didn't investigate it more closely.

But today I decided to give it a shot and started searching for the issue.  At first I thought it could be the issue(s) involved with empty collections:
 http://www.codeplex.com/wpf/WorkItem/View.aspx?WorkItemId=7960
 http://www.codeplex.com/wpf/WorkItem/View.aspx?WorkItemId=8424

But then it struck me that even for the collections that have content, the empty line at the bottom wasn't present.

Does anyone know what might cause this problem, and what I can do to work around it?

Thanx!

- Steinar

Jan 12, 2009 at 7:56 PM
At some point in time we've swapped the version of the WPF toolkit.  But I'm unable to find out what the previous version was. The current version shows up in the references in project as 3.5..31016.1.

I tried to roll back to the previous version of WPF Toolkit (to see if the upgrade was the culprit), but I was unable to build both the WPF Toolkit itself and the projects depending on it.
Jan 12, 2009 at 8:07 PM
Another data point: where the empty row is missing, we're using data binding to ItemsSource.

We have a different usage of the DataGrid, where ItemsSource is set directly to a collection, and in that case the empty row is present.
Jan 13, 2009 at 12:08 AM
Did you ever find anything on this?

As I want to get rid of the additional record.

Terry Voss
Jan 13, 2009 at 6:27 AM
Getting rid of the empty row should be as easy as setting CanUserAddRows to false.  Doesn't that work for you?

BTW what version of the DataGrid are you using?  The latest release?  And are you using data binding, or setting the ItemsSource directly to the collection the DataGrid operates on?
Coordinator
Jan 13, 2009 at 1:08 PM
Does IEditableCollectionView.CanAddNew return true?
Jan 14, 2009 at 12:26 PM
Vinsibal writes:
> Does IEditableCollectionView.CanAddNew return true?

I haven't checked that yet.

I'm afraid this was "friendly fire".  It was the aforementioned proxy wrapper object we put between the actual source object
 http://www.codeplex.com/wpf/Thread/View.aspx?ThreadId=37330
that was the culprit.

We were wrapping all list properties in an ObservableCollection<T> subclass, and  that subclass behaved strangely, and different to both IList<T> and ObservableCollection<T>:
 - the empty row at the end was gone
 - _nothing_ showed up when the properties contained empty collections

I verified that DataGrid worked ok for a plain IList<SomeClass> and almost worked for ObservablCollection<SomeClass> (it displayed the already known problem for empty ObservableCollections http://www.codeplex.com/wpf/WorkItem/View.aspx?WorkItemId=7960 )

We won't spend any time tracking the problem with our wrapping collections.  We will instead be dropping the wrapping of collection properties. There were too many places it didn't really work anyway (e.g. there were properties that just exposed IEnumerable<T> and made shallow defensive copies on both setters and getters), and it didn't handle new types of properties, such as e.g. Dictionary<string, string>.

We will be wrapping the setters and getters of the properties in the proxy.  And we will detect changes in the collections in the setters, and fire property update notifications.

We will continue to wrap IList<string> properties into lists of a class with a string property (see the above linked to thread for a recap), but we'll make this wrapper be IList<StringWrapper> rather than ObservableCollection<StringWrapper>.  Keeping it simple.  Also, using an IList avoids the issue with empty ObservableCollections.