0

I have a ICollectionView from a ObservableCollection,

 WorkingSpreadOrderCollevtionView = CollectionViewSource.GetDefaultView(SpreadOrderCollection);

my SpreadOrderCollection is not empty, as can be seen the SourceCollection count is 1

ICollectionView Watch

But why the CurrentPosition is -1, and I think because of this, DataGrid is not showing anything even I have bind the WorkingSpreadOrderCollevtionView to its ItemSourcce.

May I know what is the possible bug here?

==========================================================

Edit: The xaml binding is as follow, the DataContext is pretty sure to be correct as another public property in the same ViewModel is bind to the same xaml correctly.

<DataGrid ItemsSource="{Binding WorkingSpreadOrderCollevtionView}" CanUserAddRows="False"  AutoGenerateColumns="True" >
</DataGrid>

In addition, I can see the Columns autogenerated in the datagrid, but I just cant see the record.

==================================================

Update: I have found the dumb bug. I have called GetDefaultView twice and thinking two difference copies of the view is created, and thus applied two filters on the "two" copies. The second filter prevented the records from showing in the DataGrid. What I have done now is to create a new view as per below,

WorkingSpreadOrderCollevtionView = new CollectionViewSource { Source = SpreadOrderCollection }.View;
tesla1060
  • 2,621
  • 6
  • 31
  • 43

1 Answers1

2

CurrentPosition usually indicates selected record. Selector descendants can synchronize their SelectedItem/SelectedItemIndex with ICollectionView.CurrentItem/CurrentPosition.

The -1 value just means, that there is no selected item in the selector/collection view.

This is not related to the problem of empty DataGrid.

Dennis
  • 37,026
  • 10
  • 82
  • 150