In my WPF app I have a datagrid like
<DataGrid
SelectedItem="{Binding SelItm, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
ItemsSource="{Binding FilteredStudents}"
SelectionMode="Extended"
AutoGenerateColumns="False"
IsReadOnly="True"
SelectionUnit="FullRow"
HeadersVisibility="Column"
<DataGrid.Columns>
<DataGridTextColumn
Header="Bill No."
Binding="{Binding Path=Name, Mode=OneWay}"
Width="260"
IsReadOnly="True" />
<DataGridTextColumn
Header="Bill Date"
Binding="{Binding Path=Address, Mode=OneWay}"
Width="200"
IsReadOnly="True" />
<DataGridTextColumn
Header="Amount"
Binding="{Binding Path=Age, Mode=OneWay}"
Width="210"
IsReadOnly="True" />
</DataGrid.Columns>
</DataGrid>
The itemsource of the datagrid is an ICollectionView
called FilteredStudents
. I've created a property selrows
in my viewmodel which I binded to a label to display the selected rows count using like selrows = SelItm.Count();
.
private ICollectionView _allFilteredStudents;
public ICollectionView FilteredStudents
{
get
{
if(_allFilteredStudents == null)
{
this._allFilteredStudents = new ListCollectionView(GetAllStudents)
{
Filter = o => ((Students)o).Name != "Ram"
};
}
return _allFilteredStudents;
}
}
But it is displaying incorrect result.
BTW, my database looks like
What is the proper way to get the selected rows count of a WPF datagrid following mvvm pattern?