Custrom Filter Editors

3 posts, 1 answers
  1. Hristiliyan
    Hristiliyan avatar
    5 posts
    Member since:
    Sep 2010

    Posted 24 Nov 2010 Link to this post

    Hello,

    I want to implement a ComboBox in two of my FilterDescriptors. I do exactly the same as in the Demos, and it does not work at all. My ComboBox return value is String, I checked it and it returns the value I want. But the DataFilter does not filter the DataGrid. It work with the regular text input method, but not with the ComboBox. 

    Here is what I've done:
    <DataTemplate x:Key="RegionFilterEditorTemplate">
                <telerik:RadComboBox SelectedValue="{Binding Path=NAME, Mode=TwoWay, FallbackValue=null}" DisplayMemberPath="NAME" SelectedValuePath="NAME"
                                         MinWidth="100" SelectionChanged="RegionSelected"/>
            </DataTemplate>
            <DataTemplate x:Key="MUNFilterEditorTemplate">
                <telerik:RadComboBox SelectedValue="{Binding Path=NAME, Mode=TwoWay, FallbackValue=null}" DisplayMemberPath="NAME" SelectedValuePath="NAME"
                                         MinWidth="100" SelectionChanged="MunicipalitySelected"/>
            </DataTemplate>
            <local:MyEditorTemplateSelector x:Key="MyEditorTemplateSelector">
                <local:MyEditorTemplateSelector.EditorTemplateRules>
                    <local:EditorTemplateRule PropertyName="N_MUN.N_REGION.NAME"
                                                  DataTemplate="{StaticResource RegionFilterEditorTemplate}"/>
                    <local:EditorTemplateRule PropertyName="N_MUN.NAME"
                                                  DataTemplate="{StaticResource MUNFilterEditorTemplate}"/>
                </local:MyEditorTemplateSelector.EditorTemplateRules>
            </local:MyEditorTemplateSelector>
    <telerik:RadDataFilter Name="CitiesFilter" Source="{Binding}" Loaded="CitiesFilter_Loaded" AutoGenerateItemPropertyDefinitions="False" CanUserCreateCompositeFilters="False" EditorCreated="OnRadDataFilterEditorCreated" EditorTemplateSelector="{StaticResource MyEditorTemplateSelector}" >
                        <telerik:RadDataFilter.ItemPropertyDefinitions>
                            <datafilter:ItemPropertyDefinition PropertyName="N_MUN.N_REGION.NAME" PropertyType="{Binding String, Source={StaticResource Types}}" DisplayName="Област" />
                            <datafilter:ItemPropertyDefinition PropertyName="N_MUN.NAME" PropertyType="{Binding String, Source={StaticResource Types}}" DisplayName="Община" />
                            <datafilter:ItemPropertyDefinition PropertyName="NAME" PropertyType="{Binding String, Source={StaticResource Types}}" DisplayName="Населено място" />
                        </telerik:RadDataFilter.ItemPropertyDefinitions>
                    </telerik:RadDataFilter>
    <telerik:RadGridView x:Name="CitiesGrid" ItemsSource="{Binding FilteredSource, ElementName=CitiesFilter}"
                                         AutoGenerateColumns="False"
                                         IsReadOnly="True"
                                         ScrollMode="RealTime"
                                         CanUserReorderColumns="False"
                                         GridLinesVisibility="Both"
                                         IsFilteringAllowed="False"
                                         ShowGroupPanel="False"
                                         ColumnWidth="Auto">
                                          
                        <telerik:RadGridView.Columns>
     
     <telerik:GridViewDataColumn Header="{x:Static res:CitiesDialogFormRes.REGION}"
                                                        DataMemberBinding="{Binding Path=N_MUN.N_REGION.NAME}"
                                                        Width="Auto"/>
                            <telerik:GridViewDataColumn Header="{x:Static res:CitiesDialogFormRes.MUN}"
                                                        DataMemberBinding="{Binding Path=N_MUN.NAME}"
                                                        Width="Auto" />
                            <telerik:GridViewDataColumn Header="{x:Static res:CitiesDialogFormRes.CITY}"
                                                        DataMemberBinding="{Binding Path=NAME}"
                                                        Width="Auto" />
     
     
                        </telerik:RadGridView.Columns>
                    </telerik:RadGridView>

    And the .cs file:
                      
    private void OnRadDataFilterEditorCreated(object sender,Telerik.Windows.Controls.Data.DataFilter.EditorCreatedEventArgs e)
            {
     
                switch (e.ItemPropertyDefinition.PropertyName)
                {
                    case "N_MUN.N_REGION.NAME":
                        regionComboBox = (RadComboBox)e.Editor;
                        regionComboBox.ItemsSource = db.N_REGION.OrderBy(N_REGION => N_REGION.NAME);
                        break;
                    case "N_MUN.NAME":
                        munComboBox = (RadComboBox)e.Editor;
                        break;
                        
                }
            }
     
    private void CitiesFilter_Loaded(object sender, RoutedEventArgs e)
            {
                FilterDescriptor regionsFilterDesc = new FilterDescriptor("N_MUN.N_REGION.NAME", FilterOperator.IsEqualTo, ""true);
                FilterDescriptor munsFilterDesc = new FilterDescriptor("N_MUN.NAME", FilterOperator.IsEqualTo, ""true);
                this.CitiesFilter.FilterDescriptors.Add(regionsFilterDesc);
                this.CitiesFilter.FilterDescriptors.Add(munsFilterDesc);
            }
     
    private void RegionSelected(object sender, SelectionChangedEventArgs e)
            {
                regionComboBox = (RadComboBox)e.OriginalSource;
                var selectedRegion = regionComboBox.SelectedValue;
                munComboBox.ItemsSource = db.N_MUN.Where(N_MUN => N_MUN.N_REGION.NAME.Equals(selectedRegion)).OrderBy(N_MUN => N_MUN.NAME);
            }
  2. Answer
    Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 25 Nov 2010 Link to this post

    Hello Hristiliyan,

    Your editor control (no matter what it is) should update the Value property of the underlying ViewModel. Our ViewModel does not have a property called "NAME".

    Here is part of the online sample code:

    <DataTemplate x:Key="NameFilterEditorTemplate">
                    <telerik:RadComboBox SelectedValue="{Binding Value, Mode=TwoWay, FallbackValue=null}"
                                         MinWidth="100"/>
                </DataTemplate>

    Your custom editor should under all circumstances be bound to the Value property of the view model.

    I hope this helps. Let me know if you have any other questions.

    Best wishes,
    Ross
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for WPF
  3. UI for WPF is Visual Studio 2017 Ready
  4. Hristiliyan
    Hristiliyan avatar
    5 posts
    Member since:
    Sep 2010

    Posted 25 Nov 2010 Link to this post

    Thank you a lot ... 
Back to Top