Hello,
I use the following DataGridCollectionViewSource: (for using groups and sorting)
<my:DataGridCollectionViewSource Filter="DataGridCollectionViewSource_Filter" x:Key="usersview" Source="{dat:Binding Path=vwOffRecords, Source={x:Static Application.Current}}">
<my:DataGridCollectionViewSource.SortDescriptions>
<scm:SortDescription PropertyName="Afdeling" Direction="Ascending"/>
</my:DataGridCollectionViewSource.SortDescriptions>
<my:DataGridCollectionViewSource.GroupDescriptions>
<dat:PropertyGroupDescription PropertyName="Afdeling"/>
<dat:PropertyGroupDescription PropertyName="Verantwoordelijke"/>
</my:DataGridCollectionViewSource.GroupDescriptions>
</my:DataGridCollectionViewSource>
Together with the following Source defined in App.cs:
private Linq2SqlDataContext vwOff = new Linq2SqlDataContext();
public ObservableCollection<tblOfferten> t;
public ObservableCollection<tblOfferten> vwOffRecords
{
get
{
ObservableCollection<tblOfferten> x = new ObservableCollection<tblOfferten>(
vwOff.tblOffertens.Where(v => v.NieuweStructuur != null && v.DatumCreatie > DateTime.Parse("1/1/2008")).ToList());
t = x;
return t;
}
}
Everything works fine (sorting, grouping) and the data is just what is defined in the Linq.Where function.
But how can I change this Linq Query. I need to go through DataGridCollectionViewSource or else the sorting won't work anymore. Therefore I tried it as follows??? (but it won't work)
private void button_ChangeQuery_Click(object sender, RoutedEventArgs e)
{
Linq2SqlDataContext vwOff = new Linq2SqlDataContext();
// Get all rows
((App)App.Current).t = new ObservableCollection<tblOfferten>(vwOff.tblOffertens.Where(v => v.NieuweStructuur != null).ToList());
}
I am just looking for a way to restrict the number of rows instead of reading them all in from SQL and then filter them out.