Winform C1Flexgrid Filter By Code i.e. C#

Posted by: sanjeeb.srjm on 11 September 2021, 1:36 pm EST

  • Posted 11 September 2021, 1:36 pm EST

    Dear Sir/Mam,

    I have tried to apply some filter at runtime as follows:-

    var ffilter = new C1.Win.C1FlexGrid.ConditionFilter();

    ffilter.Condition1.Operator = C1.Win.C1FlexGrid.ConditionOperator.GreaterThanOrEqualTo;

    ffilter.Condition1.Parameter = FMiti; //variable

            var tfilter = new C1.Win.C1FlexGrid.ConditionFilter();
            tfilter.Condition1.Operator = C1.Win.C1FlexGrid.ConditionOperator.LessThanOrEqualTo;
            tfilter.Condition1.Parameter = TMiti;//variable
    
            FlxReport.ApplyFilters();
    

    the above code not filtering the record…

    Kindly request you to provide the solution…

    Regards-

    Sanjeeb

  • Posted 12 September 2021, 6:38 pm EST

    Hi Sanjeeb,

    your code snippet lacks the part where the filter is applied to the column:

    
    FlxReport.Cols[columnIndex].Filter = ffilter;
    
    

    Hope this helps

    Wolfgang

  • Posted 12 September 2021, 7:47 pm EST

    Hello Sanjeeb,

    As suggested by Wolfgang, you need to set your created filters to the particular column for which you have created it as shown in the code snippet given below:

     // Assign the new filter to "columnName" column
     c1FlexGrid1.Cols["columnName"].Filter = ffilter;
    
    https://www.grapecity.com/componentone/docs/win/online-flexgrid/filter-operations.html#2
    

    @Wolfgang, thanks for your help.

    Regards,

    Prabhat Sharma.

  • Posted 14 September 2021, 11:18 pm EST

    Dear Prabhat Sir,

    Thankx partially done …

    because we have two filter conditions ffilter and tfilter for the same column as shown above which is not working…

    please guide me sir…

    Regards-

    Sanjeeb

  • Posted 15 September 2021, 12:33 am EST

    Hi Sanjeeb,

    your original code was quite near to the goal: just create one single “ConditionFilter” and assign “Condition1” and “Condition2”.

    The property “AndConditions” defines whether the two conditions shall be combined with AND or OR.

    
          ConditionFilter combinedFilter = new ConditionFilter();
          combinedFilter.Condition1.Operator = ConditionOperator.GreaterThanOrEqualTo;
          combinedFilter.Condition1.Parameter = FMiti; //variable
    
          combinedFilter.Condition2.Operator = ConditionOperator.LessThanOrEqualTo;
          combinedFilter.Condition2.Parameter = TMiti;//variable
    
          //Combine the two filters with AND or OR:
          combinedFilter.AndConditions = true;
    
          this.c1FlexGrid.Cols[columnIndex].Filter = combinedFilter;
    
          this.c1FlexGrid.ApplyFilters();
    
    

    Best regards

    Wolfgang

  • Posted 15 September 2021, 3:41 pm EST

    Thankx a lot,

    thank you very much…

    Regards-

    Sanjeeb

  • Posted 17 September 2021, 10:48 pm EST

    Dear Sir/Mam,

    How to apply contains filter for all columns (whole row search) instead of any specific columnIndex ?

    Regards-

    Sanjeeb

  • Posted 19 September 2021, 3:40 am EST

    Dear Sir/Mam,

    Still waiting for your kind support…

    Regards-

    Sanjeeb

  • Posted 19 September 2021, 2:02 pm EST

    Hello Sanjeeb,

    You can use the ApplySearch method of FlexGrid to achieve this requirement. The code snippet is given below:

    c1FlexGrid1.ApplySearch("Text to be searched",false,true);
    

    https://www.grapecity.com/componentone/docs/win/online-flexgrid/C1.Win.FlexGrid.5~C1.Win.FlexGrid.C1FlexGridBase~ApplySearch.html

    Regards,

    Prabhat Sharma.

  • Posted 19 September 2021, 3:45 pm EST - Updated 3 October 2022, 1:44 pm EST

    Dear Prabhat Sir,

    please look at image below:-

    flxShow.ApplySearch(txtChequeType.Text, false, true);

    sir, the above apply search method have some fundamental issues as follows:-

    1. It’s not filtering only “CROSS ONLY” Row…
    2. It’s even not highlighting first occurrence row for every search…

    Kindly request you to suggest the solution…

    Regards-

    Sanjeeb

  • Posted 19 September 2021, 6:45 pm EST

    Hi Sanjeeb,

    about highligthing: set the second parameter of “ApplySearch” to true, so that the maching text is highlighted:

    
    flxShow.ApplySearch(txtChequeType.Text, true, true);
    
    

    But with this approach, it is not possible to show only the matching rows.

    I fear your requirement to search a string in all columns and show only rows that contain the filter text in any cell is not possible with the C1FlexGrid API. You would have to code it yourself:

    
    for (int row = flxShow.Rows.Fixed; row < flxShow.Rows.Count; row++)
    {
      bool matchFilter = false;
      for (int col = flxShow.Cols.Fixed; col < flxShow.Cols.Count && matchFilter == false; col++)
      {
        if (((string)flxShow[row, col]).Contains(myText) == true)
        {
          matchFilter = true;
        }
      }
      flxShow.Rows[row].Visible = matchFilter;
    }
    
    

    Hope this helps

    Wolfgang

  • Posted 20 September 2021, 8:25 pm EST

    Hello Sanjeeb,

    If your requirement is to hide the rows that do not contain the “searched text” then you can set the third parameter of the ApplySearch method to true, which will filter the search automatically.

    If there is any understanding, then please let us know and modify the attached sample accordingly.

    @Wolfgang, we can use the Filter parameter of the ApplySearch method for the same. If there is any other understanding, then please let us know.

    Regards,

    Prabhat Sharma.

    SearchDemo.zip

  • Posted 20 September 2021, 8:42 pm EST

    Dear Prabhat Sir,

    I have set third parameter to true but still not hiding the rows not matched…

    Please have a look at above image and code which I have tried with…

    Kindly request you to provide the best solution in this regard.

    Regards-

    Sanjeeb

  • Posted 21 September 2021, 6:28 pm EST - Updated 3 October 2022, 1:44 pm EST

    Hello Sanjeeb,

    We do not face the issue at our end, as shown in the attached GIF.

    If you are doing anything else as done in the attached sample, please modify it accordingly so that we can assist you further.

    Regards,

    Prabhat Sharma.

    SearchDemo (2).zip

  • Posted 22 September 2021, 1:42 am EST

    Dear Prabhat Sir,

    please check the searching

    1. by two words combination like hari raj, pratik gwali etc. it’s filtering for two words seperately…

    2. by a even single word which is in beginning and also in other part of different row. filtering will not work…

    3. also advise how to ignore columns for not to searchapply ?

    4. should ignore other than a-z, A-Z and 0-9 characters while filtering…

    5. first visible and contained row should always be selected row to take it’s data…

    please look into it…

    Regards-

    Sanjeeb

  • Posted 22 September 2021, 8:31 pm EST

    Hello Sanjeeb,

    1: For this, you need to put your string between quotes like “hari raj”, “pratik gwali” to make it search as a whole.

    This is directly not possible with the ApplySearch method to achieve other requirements. You can follow the approach suggested by Wolfgang to achieve the same as per your need.

    Although we have escalated point 3 to the developers for investigation.

    4: There is no direct property for this as it can break searching for other languages. Would you please let us know the use case so that we can investigate it further?

    2,5: Can you please elaborate on points 2 and 5 so that we can assist you accordingly?

    [Internal Tracking ID: C1WIN-25681]

    Regards,

    Prabhat Sharma.

  • Posted 24 September 2021, 12:50 pm EST

    Dear Prabhat Sir,

    Elaboration on:

    Point:4

    This feature is required when:

    suppose we have 10 columns for grabbing related data of the row for developer purpose.

    but we are showing only some columns to users as all are not needed to users at all.

    that means user always want to search/filter the rows only out of visible columns.

    and sometimes there is need even not to search by all visible columns as per user request.

    Point:5

    suppose we are searching Cat and we have two rows visible as follows:

    Blue Cat =>at row no.400

    Horrible Cat =>at row no.478

    when user type Cat for searching Blue Cat should always be selected and highlighted

    so that just by pressing enter key user will grab the data of Blue cat

    and if user needs Horrible Cat, he/she will navigate by down arrow to next row visible and then next row will be selected to grab by pressing enter key…

    Regards-

    Sanjeeb

  • Posted 27 September 2021, 9:08 pm EST

    Hello Sanjeeb,

    4: You can use the below-given overload of the ApplySearch method and set the onlyVisibleColumns property as per your need.

    public void ApplySearch( 
       string search,
       bool highlight,
       bool filter,
       bool onlyVisibleColumns,
       bool onlyVisibleRows
    )
    

    https://www.grapecity.com/componentone/docs/win/online-flexgrid/C1.Win.FlexGrid.5~C1.Win.FlexGrid.C1FlexGridBase~ApplySearch(String,Boolean,Boolean,Boolean,Boolean).html

    5: We are discussing this with the developers and will let you know the updates soon.

    Regards,

    Prabhat Sharma.

  • Posted 28 September 2021, 2:21 pm EST - Updated 3 October 2022, 1:44 pm EST

    Dear Prabhat Sir,

    Thankx. the overload worked…

    Please look into below image which has sorting problem…

    the image shows 4 rows containing “STAR” is ok…

    but it should sort the result by Begins with “STAR” First and Then Contains with “STAR”.

    result should be in below order…

    1. STAR ADVERTISING
    2. STAR WEB INFO MEDIA
    3. THREE STAR DIGITAL HOUSE
    4. MORNING STAR SCHOOL

    can we do so sir ?

    please suggest…

    Regards-

    Sanjeeb

  • Posted 28 September 2021, 8:41 pm EST

    Hello,

    There is no direct way to achieve this kind of sorting behavior but you can develop your own custom logic to implement custom sorting:

    https://www.grapecity.com/componentone/docs/win/online-flexgrid/sort-operations.html

    Regards,

    Prabhat Sharma.

  • Posted 28 September 2021, 8:41 pm EST

    Hello,

    There is no direct way to achieve this kind of sorting behavior but you can develop your own custom logic to implement custom sorting:

    https://www.grapecity.com/componentone/docs/win/online-flexgrid/sort-operations.html

    Regards,

    Prabhat Sharma.

  • Posted 29 September 2021, 1:45 am EST

    Dear Prabhat Sir,

    We are not such expert to develop such kind of advanced custom sorting logic.

    Thus, if possible please help us to do so…

    Please sir, we beg you to help us to achieve it…

    Regards-

    Sanjeeb

  • Posted 29 September 2021, 10:30 pm EST

    Hello,

    We are working on the sample and will share it with you soon.

    Regards,

    Prabhat Sharma.

  • Posted 30 September 2021, 10:00 pm EST

    Hello,

    There seems to be some issue with custom sorting and the ApplySearch method using together. So we have requested the developers to add a feature for this in the control.

    [Internal Tracking Id: C1WIN-25800]

    Regards,

    Prabhat Sharma.

  • Posted 15 November 2021, 10:47 pm EST

    Dear Prabhat Sir,

    we are still awaiting for your kind support.

    Regards-

    Sanjeeb

  • Posted 20 November 2021, 12:46 am EST

    Dear Prabhat Sir,

    please response…

    Regards-

    Sanjeeb

  • Posted 21 November 2021, 7:45 pm EST

    Hello,

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

    Regards,

    Prabhat Sharma.

  • Posted 24 December 2021, 1:27 pm EST

    Dear Prabhat Sir,

    is not there any update on this ?

    Regards-

    Sanjeeb

  • Posted 26 December 2021, 9:41 pm EST

    Hello Sanjeeb,

    The developers were busy with the release so there is no update yet.

    I am again asking them for a quick update on this issue.

    Regards,

    Prabhat Sharma.

  • Posted 2 January 2022, 9:36 pm EST

    Dear Prabhat Sir,

    Still waiting…

    Regards-

    Sanjeeb

  • Posted 11 January 2022, 1:43 pm EST

    Hello Sanjeeb,

    As per the developers, it is hard to achieve the current requirement with the existing version. They are working on this to find the solution and will reply soon.

    If it will not be possible with the existing API, then they will consider it as a feature request.

    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