C1FlexGrid custom ColumnFilter which extends default filter

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

  • Posted 19 May 2020, 9:03 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
  • Replied 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);
    }
    }
    }
    }
    If however, you don't find it feasible to use this, I would then like to learn more about the reason so that I could accordingly request the developer to extend the API.

    Thanks,
    Ruchir
  • Replied 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
  • Replied 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
Need extra support?

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

Learn More

Forum Channels