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

Override default Boolean Filtering in DataGridView WPF, Apply Custom bool filter

1 Answer 45 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Benoît
Top achievements
Rank 1
Benoît asked on 25 Aug 2017, 09:44 AM

Hello,
I would like to print custom strings in my boolean filter on a DataGridView column. I did succeed in printing my strings but I lost every Binding.

Here is my xaml here

 

<telerik:GridViewDataColumn Header="Intégrée"                  DataMemberBinding="{Binding IsIntegree, Mode=OneWay}" ShowDistinctFilters="True"/>

In the code behind I did change the output inside the filter BUT there is no more Binding from the string value ("Vrai") to the booleans values in rows ("True"):

 

private void GridView_DistinctValuesLoading(object sender, GridViewDistinctValuesLoadingEventArgs e)
        {
            var col = ((Telerik.Windows.Controls.RadGridView)sender).GetDistinctValues(e.Column, false);
             
            IEnumerable<string> enu = col.Cast<bool>().Select(t => t.ToString());
            ICollection<string> distinctValues = enu.ToList();
            distinctValues.Clear();
            distinctValues.Add("Vrai");
            distinctValues.Add("Faux");
            e.ItemsSource = distinctValues;
             
        }

The list printed in the column is done this way (code behind) :

public DemandeCotationListeView()
        {
            InitializeComponent();
            DemandeCotationListeViewModel demandeCotationViewModel = new DemandeCotationListeViewModel();
            DataContext = demandeCotationViewModel;
 
            
            for (int cpt = 2; cpt < GridView.Columns.Count; cpt++)
            {
                GridView.Columns[cpt].FilteringControl = new PersonalizedFilteringControl(GridView.Columns[cpt]);
            }
        }

How can I bind the String value to the boolean value in rows to Filter my rows ?

1 Answer, 1 is accepted

Sort by
0
Benoît
Top achievements
Rank 1
answered on 25 Aug 2017, 11:10 AM

I just had to apply the default theme to the check box which was Windows8 to keep the checkbox unchanged.

<telerik:GridViewDataColumn Header="Intégrée"                  DataMemberBinding="{Binding IsIntegree,Converter={StaticResource BooleanToStringConverter}, Mode=OneWay}" ShowDistinctFilters="True">
                <telerik:GridViewDataColumn.CellTemplate>
                    <DataTemplate>
                        <CheckBox IsChecked="{Binding IsIntegree, Mode=TwoWay}" IsEnabled="False">
                            <CheckBox.Style>
                                <Style TargetType="CheckBox">
                                    <Style.Resources>
                                        <telerik:Windows8Theme x:Key="Theme" />
                                    </Style.Resources>
                                    <Setter Property="telerik:StyleManager.Theme" Value="{StaticResource Theme}"/>
                                </Style>
                            </CheckBox.Style>
                        </CheckBox>
                    </DataTemplate>
                </telerik:GridViewDataColumn.CellTemplate>
                </telerik:GridViewDataColumn>
Tags
GridView
Asked by
Benoît
Top achievements
Rank 1
Answers by
Benoît
Top achievements
Rank 1
Share this question
or