This is a migrated thread and some comments may be shown as answers.

QueryableCollectionView Filter on event

3 Answers 102 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Khoa
Top achievements
Rank 1
Khoa asked on 20 Dec 2018, 10:39 AM

Hi,

I want my QueryableCollectionView Filter on event which invoke this function in my mainViewModel. Under is my attempt to filter this.

 

        private async Task OnContractGroupSelectionChanged()
        {
            this.ViewModelCategory.ViewModelCategory= new QueryableCollectionView(this.ViewModelCategory.CategoryData.Where(c => c.ID== this.SectionViewModle.ID));

        }

 

As you can see, I'm "newing" / creating a new instance of the QueryableCollectionView each time I choose a section in a grid.

How can I filter the QueryableCollectionView to only show items which is equal to the SectionID without having to new up an instance of the QueryableCollectionView? I can only choose one section at once, which means each time I choose a section, the QueryableCollectionView will only show the items with the same ID as the section.  I tried to add a FilterDescriptor in my MainViewModel which should update QueryableCollectionView  in my ViewModelCategory, but my program just hangs up when I try to do that.

3 Answers, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 25 Dec 2018, 08:04 AM
Hi,

Indeed, working with QCV's FilterDescriptors collection is the correct way to go. Please check the following code snippet which demonstrates how to filter a QCV:
QueryableCollectionView qcv;
 
        public MainWindow()
        {
            InitializeComponent();
 
            qcv = new QueryableCollectionView(Club.GetClubs());
            listBox.ItemsSource = qcv;
        }
 
        private void Button1_Click(object sender, RoutedEventArgs e)
        {
            //filter the qcv
            qcv.FilterDescriptors.SuspendNotifications();
 
            Telerik.Windows.Data.FilterDescriptor fd = new Telerik.Windows.Data.FilterDescriptor();
            fd.Member = "Name";
            fd.Operator = Telerik.Windows.Data.FilterOperator.IsEqualTo;
            fd.Value = "Liverpool";
            fd.MemberType = typeof(string);
 
            qcv.FilterDescriptors.Add(fd);
 
            qcv.FilterDescriptors.ResumeNotifications();
        }

I guess that your app is hanging because you are triggering a data engine update when you add a filter descriptor. In order to overcome this, you can Suspend/Resume the notifications to avoid multiple data engine updates.


Regards,
Yoan
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Khoa
Top achievements
Rank 1
answered on 07 Jan 2019, 01:35 PM

Hi, it still doesn't work...

Still freezes and hangs.

Is this because I try to invoke the filter from another viewmodel? The collection is in ViewModel2, but the MainViewModel is the one that invoke the filter add.

0
Yoan
Telerik team
answered on 10 Jan 2019, 11:55 AM
Hi,

The other ViewModel should not be the problem here. However, with the supplied information I can not figure out what may be the problem. May I ask you to isolate the issue in a sample project and send it to me. I will debug it on my side and will try to assist you further.

Regards,
Yoan
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
Khoa
Top achievements
Rank 1
Answers by
Yoan
Telerik team
Khoa
Top achievements
Rank 1
Share this question
or