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:
And the .cs file:
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);
}