WPF Datagrid

Posted by: abellisomi on 19 July 2018, 6:11 am EST

  • Posted 19 July 2018, 6:11 am EST

    Hello,
    I am using this behavior to activate the Advanced filters on the c1DataGrid (4.0.20173.580)


    <c1:C1AdvancedFiltersBehavior.AdvancedFiltersBehavior>
    <c1:C1AdvancedFiltersBehavior/>
    </c1:C1AdvancedFiltersBehavior.AdvancedFiltersBehavior>


    I would like to be able to target specific columns, not all of them. Is that possible?

    Thanks
  • Replied 19 July 2018, 6:32 pm EST

    Hi,

    Yes, it can be done.
    For this you need to subscribe to grid's AutoGeneratingColumn event and inside check for the column using e.Column.Name/e.Column.Index etc and set its CanUserFilter to False, as follows:
    private void _grid_AutoGeneratingColumn(object sender, C1.WPF.DataGrid.DataGridAutoGeneratingColumnEventArgs e)
    {
    if (e.Column.Name == "Age")
    {
    e.Column.CanUserFilter = false;
    }
    }
    This way the advanced filter would still be available to use for all columns except 'Age', which the end-user won't be able to filter.

    Thanks,
    Ruchir
  • Replied 19 July 2018, 10:32 pm EST

    That is a bit drastic: what if I would still like to have the column to filter, e.g. for Ages>18?
  • Replied 22 July 2018, 5:03 pm EST

    Hi,

    If you want to show Advanced Filters only for some column(s) and view default filters for remaining, you need to explicitly set a specific filter type for each column. Like for example if you want to show advanced filter options for FirstName column but show default filter for LastName column, you would need something like
    <c1:DataGridTextColumn Binding="{Binding FirstName}" Header="F Name" FilterMemberPath="FirstName">
    <c1:DataGridTextColumn.Filter>
    <c1:DataGridContentFilter>
    <c1:DataGridFilterList>
    <c1:DataGridTextFilter/>
    <c1:DataGridMultiValueFilter ItemsSource="{Binding EmployeeList}"/>

    </c1:DataGridFilterList>
    </c1:DataGridContentFilter>
    </c1:DataGridTextColumn.Filter>

    </c1:DataGridTextColumn>
    <c1:DataGridTextColumn Binding="{Binding LastName}" Header="L Name" FilterMemberPath="LastName"/>
    Thanks,
    Ruchir
  • Replied 23 July 2018, 2:58 am EST

    Ruchir,
    Thanks again for your timely help.
    Any reason why would this filter get overridden by the advanced filter still?


    <c1:DataGridTextColumn Header="Program" Binding="{Binding Path=ProgramName}" IsReadOnly="True" CanUserFilter="True" FilterMemberPath="ProgramName">
    <c1:DataGridTextColumn.Filter>
    <c1:DataGridContentFilter>
    <c1:DataGridTextFilter/>
    </c1:DataGridContentFilter>
    </c1:DataGridTextColumn.Filter>
    </c1:DataGridTextColumn>


    As a matter of fact, all filters get the Advanced Filter behavior.
  • Marked as Answer

    Replied 23 July 2018, 2:50 pm EST

    Hello,

    After implementing the Filters did you remove the XAML code for Advanced filters?
    Even the presence of following snippet would override all other filters, so you need to remove this code and as suggested earlier, create filters manually for all column(s) for which you want to have advanced filters and leave the Filter untouched for the remaining columns to show default filters.
    <c1:C1AdvancedFiltersBehavior.AdvancedFiltersBehavior>
    <c1:C1AdvancedFiltersBehavior />
    </c1:C1AdvancedFiltersBehavior.AdvancedFiltersBehavior>
    Thanks,
    Ruchir
  • Replied 24 July 2018, 1:15 am EST

    Oh I see, brilliant! Thanks a lot, now it works.
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels