BeginInsert() might not also work when the data items do not have a public parameterless constructor - in such situations the grid cannot create new item and respectively insert it in the source collection. If that is the case you can use the AddingNewDataItem event to manually construct new objects.
I have the same issue. I wanted to use a button click event to add a new item in my GridView
. So in the click handler I call the BeginInsert()
of my GridView
and nothing happens. I've set breakpoints and debugged and it never even goes into the AddingNewDataItem
event handler. The weird thing is that I have 2 GridViews
, but 1 works and 1 doesn't. They are both identical in terms of XAML
properties and both have an ObservableCollection<class>
for their ItemsSource
where each class has a parameterless constructor.
I would add that before I tried to use the button click to trigger the new item, I was using the ShowInsertRow="True"
property of the GridView
to where it has that first row that says, "Click here to add a new item
and on the GridView
that works, it would add the new item with one click. However, the GridView
that doesn't currently work, it required me to click that row 2 times before it would add the new item. I'm not sure if this has something to do with why the BeginInsert()
doesn't work for the button, but it definitely was the reason I moved to the button.