What I try to achieve is to apply a filter to my RadGridView whenever user checks / unchecks a checkbox (pretty straightforward, right?). My code works fine when I set the AutoGenerateColumns flag of my gridview to True, but does nothing when I switch the flag to False (the IsActive flag of my ColumnFilterDescriptor never changes to True). I need to apply a specific template to my columns so the AutoGenerateColumns flag has to be False. Both of the columns I try to filter have the IsFilterable flag to True and are binded to a string (and not a custom defined class). Here is my RadGridView:
<
Merging:RadGridViewWithSelectedItemsEditable
x:Name
=
"SelectedUserAttributesGridView"
Grid.Row
=
"0"
ItemsSource
=
"{Binding MergeDetailsViewModel}"
AutoGenerateColumns
=
"False"
VerticalAlignment
=
"Top"
CanUserDeleteRows
=
"False"
CanUserFreezeColumns
=
"False"
SelectionMode
=
"Extended"
ScrollMode
=
"Deferred"
CanUserInsertRows
=
"False"
CanUserReorderColumns
=
"True"
CanUserResizeColumns
=
"True"
CanUserSelect
=
"False"
CanUserSortColumns
=
"False"
ShowGroupPanel
=
"False"
FrozenColumnsSplitterVisibility
=
"Hidden"
GridLinesVisibility
=
"None"
RowIndicatorVisibility
=
"Collapsed"
IsEnabled
=
"{Binding MergeDetailsEnabled}"
>
<
Merging:RadGridViewWithSelectedItemsEditable.Columns
>
<
telerik:GridViewColumn
Header
=
"Well"
>
<
telerik:GridViewColumn.CellTemplate
>
<
DataTemplate
>
<
TextBlock
VerticalAlignment
=
"Center"
Margin
=
"3,0,3,0"
Text
=
"{Binding WellName}"
/>
</
DataTemplate
>
</
telerik:GridViewColumn.CellTemplate
>
</
telerik:GridViewColumn
>
<
telerik:GridViewColumn
Header
=
"UWI"
>
<
telerik:GridViewColumn.CellTemplate
>
<
DataTemplate
>
<
TextBlock
VerticalAlignment
=
"Center"
Margin
=
"3,0,3,0"
Text
=
"{Binding UWI}"
/>
</
DataTemplate
>
</
telerik:GridViewColumn.CellTemplate
>
</
telerik:GridViewColumn
>
<
telerik:GridViewColumn
Header
=
"{Binding SelectedAttributes[0].Name}"
IsFilterable
=
"True"
>
<
telerik:GridViewColumn.CellTemplate
>
<
DataTemplate
>
<
TextBlock
VerticalAlignment
=
"Center"
Margin
=
"3,0,3,0"
Text
=
"{Binding FirstSelectedAttributeValue}"
/>
</
DataTemplate
>
</
telerik:GridViewColumn.CellTemplate
>
</
telerik:GridViewColumn
>
<
telerik:GridViewColumn
Header
=
"{Binding SelectedAttributes[1].Name}"
IsFilterable
=
"True"
>
<
telerik:GridViewColumn.CellTemplate
>
<
DataTemplate
>
<
TextBlock
VerticalAlignment
=
"Center"
Margin
=
"3,0,3,0"
Text
=
"{Binding SecondSelectedAttributeValue}"
/>
</
DataTemplate
>
</
telerik:GridViewColumn.CellTemplate
>
</
telerik:GridViewColumn
>
<
telerik:GridViewColumn
Header
=
"Preview"
>
<
telerik:GridViewColumn.CellTemplate
>
<
DataTemplate
>
<
TextBlock
VerticalAlignment
=
"Center"
Margin
=
"3,0,3,0"
Text
=
"{Binding Preview}"
/>
</
DataTemplate
>
</
telerik:GridViewColumn.CellTemplate
>
</
telerik:GridViewColumn
>
</
Merging:RadGridViewWithSelectedItemsEditable.Columns
>
</
Merging:RadGridViewWithSelectedItemsEditable
>
where FirstSelectedAttributeValue and SecondSelectedAttributeValue are both string properties of my class Well, and MergeDetailsViewModel an ObservableCollection<Well>.
Here is the code of the event handler for the checkbox that applies the filter:
private
void
CheckBoxClicked(
object
sender, RoutedEventArgs e)
{
if
(ShowHideNullValuesButton.IsChecked !=
null
&& (
bool
)ShowHideNullValuesButton.IsChecked)
{
ApplyNonNullFilter(2);
ApplyNonNullFilter(3);
}
else
SelectedUserAttributesGridView.FilterDescriptors.Clear();
}
private
void
ApplyNonNullFilter(
int
columnIndex)
{
Telerik.Windows.Controls.GridViewColumn attributeValueColumn =
SelectedUserAttributesGridView.Columns[columnIndex];
IColumnFilterDescriptor attributeValueColumnFilter =
attributeValueColumn.ColumnFilterDescriptor;
attributeValueColumnFilter.SuspendNotifications();
attributeValueColumnFilter.FieldFilter.Filter1.Operator = FilterOperator.IsNotEqualTo;
attributeValueColumnFilter.FieldFilter.Filter1.Value =
"NaN"
;
attributeValueColumnFilter.FieldFilter.Filter1.IsCaseSensitive =
true
;
attributeValueColumnFilter.ResumeNotifications();
}
What am I missing? Why filtering fails? Btw, I don't get any errors or exceptions when building and running the code. Thanks.