Custom Filter

3 posts, 0 answers
  1. Lily
    Lily avatar
    14 posts
    Member since:
    Feb 2019

    Posted 18 Jun Link to this post

    Hi guys,

    So I was following this telerik video on the 3 types of filtering (basic, excel-like, custom) :  https://www.telerik.com/videos/winforms/filtering-and-expressions-in-radgridview-for-winforms

    I tried to apply the custom filtering using a textbox just like the video on my project, but I keep getting an error.  It's suppose to search all the rows and match what's in the textbox.  It'll run, but as soon as I try typing into the textbox, I get an error.  What am I doing incorrectly?

    I've attached some pics of it and the code as well.  Thank you!

     

    Here is my code:

     private void ProductionInstructionPrintPage_Load(object sender, EventArgs e)
            {
                // TODO: This line of code loads data into the 'dbMTISysDataSet.VW_ProdPrintPage' table. You can move, or remove it, as needed.
                this.vW_ProdPrintPageTableAdapter.Fill(this.dbMTISysDataSet.VW_ProdPrintPage);

                this.WindowState = FormWindowState.Maximized;

                radGridView1.EnableFiltering = true;
                radGridView1.EnableCustomFiltering = true;

            }

     

    private void radTextBox1_TextChanged(object sender, EventArgs e)
            { 

                radGridView1.MasterTemplate.Refresh();
            }

            private void radGridView1_CustomFiltering(object sender, GridViewCustomFilteringEventArgs e)
            {
                // if the custom filter is empty, reset this row to its default state
                if (string.IsNullOrEmpty(radTextBox1.Text))
                {
                    e.Visible = true;

                    //reset each cell in this row
                    for (int i=0; i<radGridView1.ColumnCount; i++)
                    {
                        e.Row.Cells[i].Style.Reset();
                        e.Row.InvalidateRow();
                    }

                    return;
                }

                //if the custom filter is set, locate the cells in this row that match it and colorize them
                e.Visible = false;
                for (int i = 0; i<radGridView1.ColumnCount; i++)
                {
                    string text = e.Row.Cells[i].Value.ToString();

                    //locate and colorize matching cells
                    if (text.IndexOf(radTextBox1.Text, StringComparison.InvariantCultureIgnoreCase) >= 0)
                    {
                        e.Row.Cells[i].Style.CustomizeFill = true;
                        e.Row.Cells[i].Style.DrawFill = true;
                        e.Row.Cells[i].Style.BackColor = Color.PowderBlue;
                        e.Visible = true;
                    }
                    else
                    {
                        e.Row.Cells[i].Style.Reset();
                        e.Row.InvalidateRow();
                    }
                }
            }

  2. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3282 posts

    Posted 19 Jun Link to this post

    Hello, Lily,

    I would recommend you to have a look at our Demo application >> GridView >> Filtering >> Custom Filtering example. You can review the C# and VB.NET code of the complete example.

    Usually the Demo application is located in the installation folder of the suite and can be found at the following path: C:\Program Files (x86)\Progress\Telerik UI for WinForms R2 2019\Examples\QuickStart\Bin

    In the C:\Program Files (x86)\Progress\Telerik UI for WinForms R2 2019\Examples\QuickStart folder, you can find the whole Examples project and examine its source code in details.
       
    I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Lily
    Lily avatar
    14 posts
    Member since:
    Feb 2019

    Posted 19 Jun in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Hi Dess,

    I'm still getting the same error...

Back to Top