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

[Solved] Filtered Event not Firing on first change of filter

3 Answers 293 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Randy
Top achievements
Rank 1
Randy asked on 23 Nov 2010, 05:35 AM
I stole this code from another post to change the background color of a column when a filter is applied.  The first problem I am having with 2010 Q3 is that the Filtered Event doesn't fire until you have chosen a second filter condition.  As you filter rows from the Telerik control, the rows are immediately filtered.  It is just that the event does not always fire.  When the event does fire sometimes the e.added and e.removed are incorrect.  What am I missing?

<telerik:RadGridView Name="_rgvEntryData" ShowGroupPanel="False"
AutoGenerateColumns="False" ShowInsertRow="True"
RowIndicatorVisibility="Collapsed" 
DataLoadMode="Asynchronous" ShowColumnFooters="True"
Margin="{StaticResource InnerMargin}"
AddingNewDataItem="_rgvEntryData_AddingNewDataItem"
Filtered="_rgvEntryData_Filtered" CanUserFreezeColumns="False" >


private void _rgvEntryData_Filtered(object sender, GridViewFilteredEventArgs e)
{
    foreach (Telerik.Windows.Data.FilterDescriptor descriptor in e.Added)
    {
        GridViewColumn column = _rgvEntryData.Columns[descriptor.Member];
        column.Background = new SolidColorBrush(Colors.Orange);
    }
    foreach (Telerik.Windows.Data.FilterDescriptor descriptor in e.Removed)
    {
        GridViewColumn column = _rgvEntryData.Columns[descriptor.Member];
        column.Background = new SolidColorBrush(Colors.Transparent);
    }
}

3 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 23 Nov 2010, 09:41 AM
Hi Randy,

The descriptors in the Filtered event are kind of fake, since it is a single big ColumnFilterDescriptor that contains all the other filters inside it. When there is any kind of filtering -- this ColumnFilterDescriptor is added to the FilterDescriptors collection of the grid. When the last sub-filter is remove, i.e. when you uncheck the last checked distinct value -- this big ColumnFilterDescriptor is removed from the FilterDescriptors collection.

Since this is the true indication about whether a column has or does not have a filter applied, I have prepared a sample project for you that does the job. Here is the important part:

using System.Collections.Specialized;
using System.Linq;
using System.Windows.Controls;
using System.Windows.Media;
using Telerik.Windows.Controls.GridView;
using Telerik.Windows.Controls;
 
namespace ColorFilteredColumn
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
 
            this.clubsGrid.FilterDescriptors.CollectionChanged += this.OnFilterDescriptorsCollectionChanged;
        }
 
        void OnFilterDescriptorsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.NewItems != null)
            {
                foreach (var columnFilterDescriptor in e.NewItems.OfType<ColumnFilterDescriptor>())
                {
                    ((GridViewColumn)columnFilterDescriptor.Column).Background = new SolidColorBrush(Colors.Orange);
                }
            }
             
            if (e.OldItems != null)
            {
                foreach (var columnFilterDescriptor in e.OldItems.OfType<ColumnFilterDescriptor>())
                {
                    ((GridViewColumn)columnFilterDescriptor.Column).Background = new SolidColorBrush(Colors.Transparent);
                }
            }
        }
    }
}

I hope this helps.

Best wishes,
Ross
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Randy
Top achievements
Rank 1
answered on 24 Nov 2010, 02:56 AM
Thank you for your fast response!

This works great, but can I ask for one more thing?  I was using the filtered event to run a calculate on a function for a special footer being used like an aggregrate total (only counts records if a different field on the grid is set for that row).  It works fine WHEN the filtered event fires.  Problem is that the filtered event only fires after the second filter is added.
0
Rossen Hristov
Telerik team
answered on 24 Nov 2010, 12:17 PM
Hi Randy,

I have prepared a sample project in order to reproduce this, but unfortunately I could not. Here is a movie of what I did.

What are the exact steps I need to do in order to get the Filtered event not to fire?

The sample project is attached. I am looking forward to hearing from you.

Greetings,
Ross
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
Tags
GridView
Asked by
Randy
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Randy
Top achievements
Rank 1
Share this question
or