Highlighting Filtered Items

4 posts, 0 answers
  1. Ryan Abbott
    Ryan Abbott avatar
    9 posts
    Member since:
    Jul 2007

    Posted 18 Feb 2011 Link to this post

    I'm trying to highlight (change background color of) the actual rows that have the data I'm filtering for, but it doesn't seem to be working. Basically, when I filter it will show the filtered items along with their parent rows in the hierarchy (which may not have the data I'm filtering for, but from my understanding need to be there to show the child item).

    I tried following the Telerik example for the GridView, where it highlights the filtered column, and that works fine. I'm currently testing to see if I can just highlight a cell and it isn't working. Below is my code.

    private void MyGridView_Filtered(object sender, Telerik.Windows.Controls.GridView.GridViewFilteredEventArgs e)
            {
                foreach(FilterDescriptor descriptor in e.Added)
                {
                    GridViewColumn column = MyGridView.Columns[descriptor.Member];
                     
                    foreach(var item in MyGridView.Items)
                    {
                        var match = item;
                        if (descriptor.Operator == FilterOperator.IsGreaterThan && item.Value > Convert.ToInt32(descriptor.Value))
                        {
                            Dispatcher.BeginInvoke(new Action(() =>
                            {
                                MyGridView.CurrentCellInfo = new GridViewCellInfo(match, column);
                                MyGridView.CurrentCell.Background = new SolidColorBrush(Colors.Green);
                            }));
                        }
                    }
                }
    }
  2. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 24 Feb 2011 Link to this post

    Hello Ryan ,

    I was trying to find a good solution for this one . Setting the background directly would not do the trick as scrolling and expand /collapse operations would reset the cell.

    Though it is not straightforward , there might be a solution:
    You can try setting the cell background using a CellStyleSelector.
    The style selector itself should be something like :
    public class ConditionalStyleSelector : StyleSelector
       {
           public override System.Windows.Style SelectStyle(object item, System.Windows.DependencyObject container)
           {
                           
                   //Check here if the cell matches the criteria and return a Style setting the background and targeting GridViewCell
           }
       }
    * from within the method you can get the parent TreeListView the following way:
    container.ParentOfType<RadTreeListView>(). This will give you access to the filterdescriptors so you can build your condition.

    In case you find troubles implementing this , do not hesitate to open a support ticket reffering this thread and attach your project ( or a small repro) . I can implement this behaviour directly inside  and send the modified version back  to you .

    Regards,
    Pavel Pavlov
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  3. DevCraft banner
  4. Ryan Abbott
    Ryan Abbott avatar
    9 posts
    Member since:
    Jul 2007

    Posted 24 Feb 2011 Link to this post

    Thanks Pavel, I think I understand the logic for this. Is it possible to see the code in the Examples file that's referenced in the link?

    <Examples:UnitPriceConveter x:Key="converter" />
                <Examples:ConditionalStyleSelector x:Key="selector" ConditionConverter="{StaticResource converter}">
                    <Examples:ConditionalStyleSelector.Rules>
                        <Examples:ConditionalStyleRule Style="{StaticResource HighUnitPriceStyle}">
                            <Examples:ConditionalStyleRule.Value>
                                <sys:Boolean>True</sys:Boolean>
                            </Examples:ConditionalStyleRule.Value>
                        </Examples:ConditionalStyleRule>
                        <Examples:ConditionalStyleRule Style="{StaticResource LowUnitPriceStyle}">
                            <Examples:ConditionalStyleRule.Value>
                                <sys:Boolean>False</sys:Boolean>
                            </Examples:ConditionalStyleRule.Value>
                        </Examples:ConditionalStyleRule>
                    </Examples:ConditionalStyleSelector.Rules>
                </Examples:ConditionalStyleSelector>

    Ideally I'd like to highlight the entire row that meets the filter criteria, but for now just getting it to highlight the cell would be helpful to me.

    Thanks!
  5. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 28 Feb 2011 Link to this post

    Hello Ryan ,

    I am attaching the code of the style selector for the example requested. The rest of the example  code you may see by clicking "view code " in the example itself.

    Kind regards,
    Pavel Pavlov
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Back to Top