Welcome to the Xceed Community Sign in | Join | Help
Community Search  

How to programmaticly change the Linq Query for DataGridCollectionViewSource?

Sort Posts: Previous Next
  •  06-10-2008, 7:55 AM Post no. 12796

    How to programmaticly change the Linq Query for DataGridCollectionViewSource?

    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.

  •  06-10-2008, 8:28 AM Post no. 12803 in reply to 12796

    Re: How to programmaticly change the Linq Query for DataGridCollectionViewSource?

    You can take a look at the LINQ to SQL example in the Providing Data topic for an example of how to use the grid with LINQ and how to change the content displayed by the grid by changing the query when a new value is selected in the combobox.

    Technical Writer - Xceed Software

    Of all the things I've lost, I miss my mind the most. - Mark Twain
    Filed under: ,
  •  06-10-2008, 4:01 PM Post no. 12824 in reply to 12803

    Re: How to programmaticly change the Linq Query for DataGridCollectionViewSource?

    Hello Jenny,

    Yes!! It seems to work. (I read this in the beginning but later on i forgot this approach)
    Already thanks a lot for this TIP !!!!!Yes

    But I still have a strange behaviour (that I also saw when I did my tests) I think it could be a DataGrid Problem:

    The ScrollTip doesn't seem to work when it is configured like this (Query in Window instead of the App...).
    I only see a filled circle with nothing in it, and yes MainColumn is set to true in 1 column:
    <xcdg:Column FieldName="Projectnr" IsMainColumn="True" Title="Projectnr" />

    In my previous tests it also would not work if you set AutoCreateColumns="False". (and the IsMainColumn was correctly filled in!)

    Any idea? A bug? Not working in this sample?  

    Korstiaan

  •  06-11-2008, 8:37 AM Post no. 12859 in reply to 12824

    Re: How to programmaticly change the Linq Query for DataGridCollectionViewSource?

    I have reproduced this behavior and have created a ticket for it. I will let you know when I have more information.
    Technical Writer - Xceed Software

    Of all the things I've lost, I miss my mind the most. - Mark Twain
  •  06-12-2008, 3:32 PM Post no. 12921 in reply to 12859

    Re: How to programmaticly change the Linq Query for DataGridCollectionViewSource?

    We found the problem for the ScrollTip and it will be fixed in next release.

    You can workaround this issue by affecting the UIViewBase.ScrollTipContentTemplate manually with a DataTemplate for your MainColumn.

    Thanks for reporting this issue!


    Christian Nadeau
    Software Developer
    Xceed Software Inc.
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2008 Xceed Software Inc.