WPF Datagrid - Advanced Filters behavior

Posted by: abellisomi on 21 May 2020, 11:12 am EST

    • Post Options:
    • Link

    Posted 21 May 2020, 11:12 am EST

    Hello,

    I am using the advanced filter on the DataGrid and I would like to apply a behavior similar to Excel. Let’s suppose I have the following dataset and both Field1 and Field2 support advanced filter.

    
    Field1   Field2
    1           A
    2          A
    3          B
    1           C
    
    

    If I open the dropdown filter for Field2 I will have three checkboxes in the list [A B C]. In the C1:DataGrid component, if I filter Field1=1, the Field2 filter is still going to show me all the available options [A B C]. Ideally, I would like to have [A C] as only option for Field2 because the only occurrences with Field1=1 on Field2 are [A C]. Is it something achievable?

    Thank you

  • Posted 21 May 2020, 9:43 pm EST

    Hi,

    If you want to use C1AdvancedFiltersBehavior you should re-write the filter dropdown containing values only from the filtered out rows.

    This can be done by setting the ItemsSource of MultiValueFilter for any column to only visible(or filtered out) values as follows : ```

    multiValueFilter.ItemsSource = GetColumnValues(e.Column);

    bool add = false;

    for (int r = 0; r < DataGrid.Rows.Count; r++)

    {

    if (DataGrid[r, index].Text.Equals(valueString) && DataGrid.Rows[r].Visibility.Equals(Visibility.Visible))

    {

    add = true;

    break;

    }

    }

    
    Thanks,
    Ruchir[zip filename="C1DataGrid_AdvFilters.zip"]https://gccontent.blob.core.windows.net/forum-uploads/file-b96072c5-f604-414a-bb71-32a4e67b1d59.zip[/zip]
  • Posted 21 May 2020, 10:02 pm EST

    This works perfectly, thank you!

Need extra support?

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

Learn More

Forum Channels