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

Highlighting Filtered Items

3 Answers 88 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
Ryan Abbott
Top achievements
Rank 1
Ryan Abbott asked on 18 Feb 2011, 08:38 PM
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);
                        }));
                    }
                }
            }
}

3 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 24 Feb 2011, 10:27 AM
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!
0
Ryan Abbott
Top achievements
Rank 1
answered on 24 Feb 2011, 11:35 PM
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!
0
Pavel Pavlov
Telerik team
answered on 28 Feb 2011, 05:39 PM
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!
Tags
TreeListView
Asked by
Ryan Abbott
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Ryan Abbott
Top achievements
Rank 1
Share this question
or