This is a migrated thread and some comments may be shown as answers.

Custom Filter

3 Answers 305 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Lily
Top achievements
Rank 1
Veteran
Lily asked on 18 Jun 2019, 07:03 PM

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();
                }
            }
        }

3 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 19 Jun 2019, 12:15 PM
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.
0
Lily
Top achievements
Rank 1
Veteran
answered on 19 Jun 2019, 03:21 PM

Hi Dess,

I'm still getting the same error...

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 24 Jun 2019, 08:44 AM
Hello, Lily,  

Following the referred example in our Demo application, I have prepared a sample project for your convenience. Please refer to the attached zip file. The provided gif file illustrates the behavior on my end. Everything seems to work as expected.

Am I missing something? Could you please specify the exact steps how to reproduce the problem?

I am looking forward to your reply.

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.
Tags
GridView
Asked by
Lily
Top achievements
Rank 1
Veteran
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Lily
Top achievements
Rank 1
Veteran
Share this question
or