Filter TrueDbGrid

Posted by: info on 11 December 2022, 5:03 am EST

    • Post Options:
    • Link

    Posted 11 December 2022, 5:03 am EST

    Hello,

    when I enable the filter on a column of a grid,

    Basically, the search is done by “Starts with”.

    But what if you wanted to search by Contains?

    For example, I have the following values:

    Frank Sinatra

    Rihanna

    Katy Perry

    Christina Aguilera

    If I search for Chr, the Christina Aguilera filter is returned correctly.

    But what if you wanted to search for agui? With basic filters it doesn’t return everything.

    Thanks, regards

  • Posted 11 December 2022, 11:44 pm EST

    Hello Marco,

    To achieve this type of filtering functionality you need to set the AllowFilter property to False and handle the FilterChange event as per your requirement.

    private void c1TrueDBGrid1_FilterChange(object sender, System.EventArgs e)

    {

    // build our filter expression

    StringBuilder sb = new StringBuilder();

    		foreach(C1.Win.C1TrueDBGrid.C1DataColumn dc in this.c1TrueDBGrid1.Columns)
    		{
    			if( dc.FilterText.Length > 0 )
    			{
    				if( sb.Length > 0 ) sb.Append(" AND ");
                                        // Contains Filter
    				sb.Append(dc.DataField + " like " + "'*" + dc.FilterText + "*'");
    			}
    		}
    		// filter the data
    		this.dataSet11.Tables[0].DefaultView.RowFilter = sb.ToString();
    	}
    

    Please find the attached sample implementing the same.

    Regards,

    Prabhat Sharma.

    CustomFiltering.zip

  • Posted 12 December 2022, 6:56 am EST

    Hello Prabhat,

    thanks for the reply.

    However it would be more convenient and standard if it were handled as a built-in feature.

    I think the component recommends migrating from TrueDbGrid to FlexGrid.

    Do you confirm that it is the right way and that we can get the same results, if not better?

    Thank you.

  • Posted 14 December 2022, 1:21 am EST

    Hello Marco,

    If you do not want to handle the FilterChange event then you can use the FilterOperator property of the specified column as given in the code snippet below:

    c1TrueDBGrid1.Columns[columnIndex].FilterOperator = “%LIKE%”;

    https://www.grapecity.com/componentone/docs/win/online-truedbgrid/C1.Win.C1TrueDBGrid.4.5.2~C1.Win.C1TrueDBGrid.C1DataColumn~FilterOperator.html

    FlexGrid is our flag-shipped grid control which has some advanced functionalities. Earlier we were not in the plan to migrate to TrueDBGrid to the latest version but as a lot of customers are using C1TrueDBGrid control in their projects so we decided to migrate it as well.

    If you wish to migrate to FlexGrid, you need to write the code from scratch but first please make sure it fulfills all your requirement.

    https://www.grapecity.com/blogs/reasons-to-migrate-truedbgrid-to-flexgrid-in-winforms-datagrid-application

    There is no direct filter bar in FlexGrid, to implement it you can see the FilterRow product sample at the location:

    …\Documents\ComponentOne Samples\WinForms\v4.5.2\FlexGrid\CS\FilterRow

    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