I have a GridViewComboBoxColumn that I have added a Composite Filter descriptor to, so that I can Filter based upon the text description of the combobox rather than the ID's which are the default. I have used the sample here as the basis of my code. The filter works perfectly, but the "Filtered" event is not firing when the composite filter is executed.
Is this normal? I have included my code as an example. Any help would be greatly appreciated.
Is this normal? I have included my code as an example. Any help would be greatly appreciated.
public
partial
class
SalesStageFilterControl : UserControl, IFilteringControl
{
private
GridViewComboBoxColumn _column;
private
CompositeFilterDescriptor _compositeFilterDescriptor;
public
SalesStageFilterControl()
{
InitializeComponent();
}
public
static
readonly
DependencyProperty IsActiveProperty = DependencyProperty.Register(
"IsActive"
,
typeof
(
bool
),
typeof
(SalesStageFilterControl),
new
PropertyMetadata(
false
));
#region IFilteringControl Members
public
bool
IsActive
{
get
{
return
(
bool
)GetValue(IsActiveProperty);}
set
{ SetValue(IsActiveProperty, value);}
}
#endregion
public
void
Prepare(GridViewBoundColumnBase column)
{
if
(_compositeFilterDescriptor ==
null
)
{
_compositeFilterDescriptor =
new
CompositeFilterDescriptor {LogicalOperator = FilterCompositionLogicalOperator.Or};
_column = column
as
GridViewComboBoxColumn;
listBoxSalesStage.ItemsSource = ((ViewModels.OpportunityViewModel)(_column.ItemsSourceBinding.Source)).SalesStages;
listBoxSalesStage.DisplayMemberPath = _column.DisplayMemberPath;
listBoxSalesStage.SelectedValuePath = _column.SelectedValueMemberPath;
}
}
private
void
ListBoxSalesStageSelectionChanged(
object
sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
_compositeFilterDescriptor.FilterDescriptors.Clear();
foreach
(var item
in
listBoxSalesStage.SelectedItems)
{
var propertyInfo = item.GetType().GetProperty((_column).SelectedValueMemberPath);
var itemValue = propertyInfo.GetValue(item,
null
);
_compositeFilterDescriptor.FilterDescriptors.Add(
new
FilterDescriptor(_column.DataMemberBinding.Path.Path, FilterOperator.IsEqualTo, itemValue));
}
if
(_compositeFilterDescriptor.FilterDescriptors.Count > 0)
{
if
(!_column.DataControl.FilterDescriptors.Contains(_compositeFilterDescriptor))
{
_column.DataControl.FilterDescriptors.Add(_compositeFilterDescriptor);
}
IsActive =
true
;
}
else
{
if
(_column.DataControl.FilterDescriptors.Contains(_compositeFilterDescriptor))
{
_column.DataControl.FilterDescriptors.Remove(_compositeFilterDescriptor);
}
IsActive =
false
;
}
}
}