Search code examples
c#wpfdatagrid

Datagrid results do not make sense


I've been working with the DataGrid in WPF with great results. However, it is now giving me unexpected results after some changes.

BEFORE: I had a DataGrid on a page. The DataContext was set to a List object that was created from a class that existed within the same WPF project. The empty row at the bottom of the DataGrid, to add new records, is visible

AFTER: Same page, same DataGrid. But now the List object is coming from a Class Library project within the same solution. EXACT same code, but it's now been extracted into a class library. The empty row at the bottom of the datagrid, to add new records is not visible.

WTF?


Solution

  • Maybe it is some security issue or even a bug. I just read this:

    I found that if you access the CanAddRow of ListCollectionView once before you use the collection, magically the CanUserAddRows of the DataGrid becomes true. Strange!

    IEditableCollectionView ecv = new ListCollectionView(myRecordCache);
    bool b = ecv.CanAddNew;   // dummy access
    MyGrid.DataContext = ecv;