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

GridView for WPF: Custom filter

3 Answers 261 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Marco A
Top achievements
Rank 1
Marco A asked on 06 Oct 2008, 10:27 PM
Hi,
I'm testing wpf controls, i would like to know if is there a way to customize the automatic filter with something like a textbox and a combo, or add a custom row where i can put some controls to create a custom filter. Sorry for my english.

Thanks

Marco

3 Answers, 1 is accepted

Sort by
0
Atanas
Telerik team
answered on 08 Oct 2008, 11:57 AM
Hi Marco A,

In the attached sample you will find a RadGridView that uses combo boxes to perform filtering. First, we create a control template for the DistinctFilterControl, the control that realizes the filtering process.
 
        <ControlTemplate x:Key="FilterControlTemplate" TargetType="{x:Type telerik:DistinctFilterControl}"
            <StackPanel> 
                <StackPanel Orientation="Horizontal"
                    <ComboBox IsEditable="True" IsReadOnly="False" Name="comboBoxDistinctValues" 
                                MaxHeight="500" HorizontalAlignment="Stretch" Width="70" 
                                ItemsSource="{TemplateBinding DistinctValues}" 
                                Loaded="ComboBox_Loaded"  
                                SelectionChanged="ComboBox_SelectionChanged" /> 
                    <telerik:ClearFilterButton Margin="0,0,0,5" Content="Clear Filter" 
                                            Target="{Binding ElementName=comboBoxDistinctValues, Mode=OneTime}"  
                                            FilterDescription ="{TemplateBinding FilterDescription}" /> 
                </StackPanel> 
            </StackPanel> 
        </ControlTemplate> 
        <Style TargetType="{x:Type telerik:DistinctFilterControl}"
            <Setter Property="Template" Value="{StaticResource FilterControlTemplate}" /> 
        </Style> 

You can see the combo box (named "comboBoxDistinctValues") that contains the values you can filter by. Our button, that clears your filter, is retained in the template.

You will notice that the events Loaded and SelectionChanged of the combo box are handled in the code-behind. The handler of Loaded:

 
ComboBox comboBox = (ComboBox) sender; 
DistinctFilterControl filterControl = this.GetVisualParent<DistinctFilterControl>(comboBox); 
this.PopulateDistinctValues(string.Empty, filterControl); 

calls the method "PopulateDistinctValues":
 
GridViewHeaderCell headerCell = this.GetVisualParent<GridViewHeaderCell>(filterControl); 
 
string propertyName = ((IColumnInfo) headerCell).PropertyName; 
 
GridViewDataControl gridControl = this.GetVisualParent<GridViewDataControl>(filterControl); 
filterControl.DistinctValues = gridControl.ItemsControl.RecordManager.GetDistinctValues(propertyName); 

which fills the combo box with the values you can use for filtering. The event handler for SelectionChanged:

 
ComboBox comboBox = (ComboBox) sender; 
DistinctFilterControl filterControl = this.GetVisualParent<DistinctFilterControl>(comboBox); 
FieldFilterDescription filterDescription = filterControl.FilterDescription; 
 
IList valueCollection; 
if (e.AddedItems.Count > 0) 
   valueCollection = e.AddedItems; 
   foreach (object value in valueCollection) 
   { 
       filterDescription.Values.Add(value); 
   } 
 
if (e.RemovedItems.Count > 0) 
    valueCollection = e.RemovedItems; 
    foreach (object value in valueCollection) 
    { 
        if ((comboBox.Items.IndexOf(value) != -1)) 
            filterDescription.Values.Remove(value); 
    } 

changes the filtering whenever you select a new value in the combo box.

As far as the filtering row is concerned, we do not currently support this feature in RadGridView. However, it is on our to-do list and will be available in future versions.

We will be glad to answer any other questions of yours.

Greetings,
Atanas
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Ivo
Top achievements
Rank 1
answered on 10 Oct 2008, 11:54 AM
Hi,

We're also looking for a wpf grid control offering fully customizable grid view with a filter-row. Do you have any idea when this will be available? And in the meantime, do you know of some possible workarounds?

thanks,
Ivo
0
Hristo Deshev
Telerik team
answered on 10 Oct 2008, 01:05 PM
Hi Ivo,

At the moment we are thinking about offering the feature in Q1 2009, but I cannot commit to that date yet.

The only workaround I can think of at the moment is building your own Filtering UI that will feed a FilterDescription to the RadGridView control.

Regards,
Hristo Deshev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
GridView
Asked by
Marco A
Top achievements
Rank 1
Answers by
Atanas
Telerik team
Ivo
Top achievements
Rank 1
Hristo Deshev
Telerik team
Share this question
or