C1FlexGrid custom ColumnFilter which extends default filter

Posted by: wknauf on 19 May 2020, 9:03 pm EST

    • Post Options:
    • Link

    Posted 19 May 2020, 9:03 pm EST - Updated 3 October 2022, 1:25 pm EST

    Hi C1,

    a customer wants fo filter datetime values in a FlexGrid column by day of week. I found a way to reuse the existing datetime filter and extend it with a “Day of week” filter, see attached sample and screenshot:

    I did so by implementing a “IC1ColumnFilter” which encapsulates a “ColumnFilter” and also has additional properties for the weekday filter.

    In the UI, I added two radiobuttons to toggle beetween standard filter and weekday filter. Here comes the ugly part: in order to use the default filter control, I had to use reflection, because the type “ColumnFilterEditor” is internal:

    
          string strAssembly = typeof(IC1ColumnFilterEditor).Assembly.GetName().Name;
          Type typeColFilterEditor = Type.GetType("C1.Win.C1FlexGrid.ColumnFilterEditor," + strAssembly, true);
          IC1ColumnFilterEditor filterEditorDefault = (IC1ColumnFilterEditor) Activator.CreateInstance(typeColFilterEditor);
    
    

    But I don’t like this UI, because there are two places where you switch beetween filters:

    -my two radiobuttons

    -the buttons “Value filter”/“Conditional filter” in the standard filter.

    Is there any chance to extend/subclass the “ColumnFilterEditor” so that I can add a third toggle button “weekday” to the ToolStrip which shows my custom panel “day of week”?

    Probably this is a question for the developers, as the API would have to be enhanced.

    And please make “ColumnFilterEditor” a public class so I can instanciate it ;-).

    Best regards

    Wolfgang

    FlexFilterDateTime.zip

  • Posted 21 May 2020, 5:32 am EST

    Hello Wolfgang,

    Thank you for sharing the application as well as describing the use-case in detail.

    However, as I understand, you are looking to add a Toggle button in the toolstrip of the Filter Editor Form. If that is the case, I would like to point out an approach that might be aware of. The approach is to access the filter editor form’s toolstrip at run-time and add the control then?

    Similar to following:```

    private void C1FlexGrid1_MouseDown(object sender, MouseEventArgs e)

    {

    C1.Win.C1FlexGrid.HitTestInfo ht = c1FlexGrid1.HitTest(e.Location);

    if(ht.Type== C1.Win.C1FlexGrid.HitTestTypeEnum.FilterIcon)

    {

    foreach (Form frm in Application.OpenForms)

    {

    if (frm.Name == “FilterEditorForm” && frm.GetType().ToString() == “C1.Win.C1FlexGrid.FilterEditorForm”)

    {

    ToolStripSplitButton weekdayFilter = new ToolStripSplitButton();

    weekdayFilter.Name = “_btnWeekdayFilter”;

    weekdayFilter.Text = “&Weekday Filter”;

    weekdayFilter.Click += WeekdayFilter_Click;

    (frm.Controls[0] as ToolStrip).Items.Add(weekdayFilter);

    }

    }

    }

    }

    
    Thanks,
    Ruchir
  • Posted 23 May 2020, 12:06 am EST

    Hi Ruchir,

    actually, I thought about this approach too. But it seems too hacky for me and might break whenever you change the control, because the compiler does not tell me anything about this.

    Also, your sample stops at the interesting part ;-): I have to add my custom filter panel to it and toggle its visibility when my toolbar button or of the standard buttons is clicked. But this is no magic, just a bit of coding…

    Is it possible to make the “FilterEditorForm” class public, the toolbar and its buttons and the filter panels protected, so that I could subclass the form and add (by designer or by code) my custom controls?

    Best regards

    Wolfgang

  • Posted 25 May 2020, 9:07 pm EST

    Hello,

    Thank you for sharing your concern using FilterEditorForm approach. So, I have now forwarded your request to the developers [ID: 438031].

    We will update this thread as soon as we receive some information.

    Regards,

    Ruchir

  • Posted 3 May 2021, 10:04 pm EST

    Hi,

    any updates on this?

    Best regards

    Wolfgang

  • Posted 4 May 2021, 3:34 pm EST

    Hello,

    We are getting in touch with the developers for the updates and will let you know soon.

    Regards,

    Prabhat Sharma.

  • Posted 13 September 2021, 7:16 pm EST

    Any Update on this?

  • Posted 19 June 2022, 7:51 pm EST

    Hi C1,

    any updates on this?

    Best regards

    Wolfgang

  • Posted 19 June 2022, 10:20 pm EST

    Hello Wolfgang,

    Apologies for the delay in response.

    The last time when we checked the issue with the developers, it was there on their to-do list.

    I am getting in touch with them to get the ETA if any.

    Regards,

    Prabhat Sharma.

  • Posted 13 December 2022, 9:32 pm EST - Updated 13 December 2022, 9:37 pm EST

    As I found a change about column filters in the readme, I gave it another try. And I think my sample works much better now: in my “IC1ColumnFilterEditor” implementation, I can add the default “C1.Win.C1FlexGrid.ColumnFilterEditor” at design time instead of having to use reflection.

    Attached is an updated sample:

    FlexFilterDateTime_2022-12-14.zip

    There is also a sample “AdvancedFilters” which seems to be inspired by my original issue ;-): https://github.com/GrapeCity/ComponentOne-WinForms-Samples/tree/master/Core/FlexGrid/CS/FlexGridExplorer/Samples/AdvancedFilters

    But I will stay with my original approach to use two radio buttons to switch the filter mode, as the dropdown is very hidden. And never change running code ;-).

    Also, the “Avanced Filtering” sample seems to have a layout issue: the “Apply filter” button is hidden in the dropdown menu. Seems the filter popup is too small:

    Best regards

    Wolfgang

  • Posted 14 December 2022, 7:49 pm EST - Updated 14 December 2022, 7:55 pm EST

    Hello Wolfgang,

    We do agree that the filter popup is too small. Please find the attached sample with the dropdown in the filter form visible clearly.

    Also, we can see the Apply button in the "Advanced Filtering” sample, please see the attached screenshot for reference.

    But I will stay with my original approach to use two radio buttons to switch the filter mode, as the dropdown is very hidden.

    This also looks nice. Thanks for sharing the sample :slight_smile:

    Regards,

    Prabhat Sharma.

    FlexGrid_QuickStart_Mod4.zip

  • Posted 14 December 2022, 9:57 pm EST

    The missing “Apply” button might be related to my locale - the german texts are much longer than the english defaults.

    Best regards

    Wolfgang

  • Posted 15 December 2022, 4:36 pm EST - Updated 15 December 2022, 4:41 pm EST

    Hello Wolfgang,

    Yes, your understanding is correct, the apply button is hidden because the form width has less space.

    You can change the width of the filter form in the InheritedFilterEditorNewMenu file to get all the menu options in a single row.

    Regards,

    Prabhat Sharma.

  • Posted 15 December 2022, 7:18 pm EST

    Thanks. For my implementation, that is not a problem, but I thought it might be helpful to fix the sample.

    Best regards

    Wolfgang

  • Posted 18 December 2022, 11:33 pm EST

    Hello Wolfgang,

    We have raised this concern to the development team and will get it fixed soon.

    Regards,

    Prabhat Sharma.

Need extra support?

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

Learn More

Forum Channels