none
CollectionViewSource Filtering RRS feed

  • Question

  • Hi guys

    Im a little stuck with filtering a collection viewsource.

    I currently have the XAML below with a datagrid bound to it.

    <CollectionViewSource x:Key="counterfeitPartsViewSource" d:DesignSource="{d:DesignInstance my:CounterfeitPart, CreateList=True}" Filter="CollectionViewSource_Filter" />

    How can I code the CollectionViewSource_Filter event to filter depending on a combo box selection?

    Or am I missing something here?

    Thanks,

    Dean

    Wednesday, November 21, 2012 9:35 AM

Answers

  • Hi Alexander,

    I will post my problem on the other forum as well. I am already fetching the data using entity framework, its filtering that data that im struggling with.

    Thanks,

    Dean.

    • Marked as answer by Alexander Sun Friday, December 7, 2012 2:05 AM
    Thursday, November 22, 2012 10:01 AM

All replies

  • Hi Dean,

    Welcome to the MSDN forum.

    Is the CollectionViewSource a WPF control?

    Have a nice day.


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, November 22, 2012 3:01 AM
  • Hi Alexander,

    Yes it is. Just to add. Im literally at the stage where I have created the entity framework with 2 tables in (parent and child link). Ive dragged the parent datagrid into the window and the code below has been automatically generated, I want to filter this based on a drop down elsewhere in the window. Im just looking for the simplest solution.

                Trial.CounterfeitEntities counterfeitEntities = new Trial.CounterfeitEntities();
                System.Windows.Data.CollectionViewSource counterfeitPartsViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("counterfeitPartsViewSource")));
                System.Data.Objects.ObjectQuery<Trial.CounterfeitPart> counterfeitPartsQuery = this.GetCounterfeitPartsQuery(counterfeitEntities);
                counterfeitPartsViewSource.Source = counterfeitPartsQuery.Execute(System.Data.Objects.MergeOption.AppendOnly);

    Many Thanks,

    Dean.

    Thursday, November 22, 2012 8:07 AM
  • Hi Dean,

    I am not very familiar with WPF, but I think you could add your source binding code in the event of combo box like SelectionChanged. If you need some help about binding code, please try WPF forum: http://social.msdn.microsoft.com/forums/en-US/wpf/threads/

    If you want to know how to fetch data via Entity Framework, could you please let me know some specific problem you encountered?

    Have a nice day.


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, November 22, 2012 9:23 AM
  • Hi Alexander,

    I will post my problem on the other forum as well. I am already fetching the data using entity framework, its filtering that data that im struggling with.

    Thanks,

    Dean.

    • Marked as answer by Alexander Sun Friday, December 7, 2012 2:05 AM
    Thursday, November 22, 2012 10:01 AM