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

Rows do not show up in grid after clearing filter text

4 Answers 118 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Randy
Top achievements
Rank 1
Randy asked on 21 Jun 2013, 02:36 PM
I am using a combination of normal and custom filtering in the RadGridView control.  When the user clears the text out of a filter box in the filtering row the grid still filters as if the box still had text in it.

In the attached image you can see that two rows show up in the grid initially.

After the filter value Contains "T" is entered the first row is correctly filtered.

When I clear that filter box the first row remains hidden.  The only way to get the grid to show the row again is to set the filter type to "No Filter" and then back to "Contains".

Here is the sample code:
public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
 
            radGridView1.CustomFiltering += radGridView1_CustomFiltering;
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            radGridView1.MasterTemplate.Columns.Clear();
             
            GridViewTextBoxColumn v1Col = new GridViewTextBoxColumn("Value1");
            v1Col.Name = "Value1";
            radGridView1.MasterTemplate.Columns.Add(v1Col);
 
            GridViewTextBoxColumn v2Col = new GridViewTextBoxColumn("Value2");
            v2Col.Name = "Value2";
            radGridView1.MasterTemplate.Columns.Add(v2Col);
 
            radGridView1.MasterTemplate.EnableFiltering = true;
            radGridView1.MasterTemplate.EnableCustomFiltering = true;
            radGridView1.MasterTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
 
            BindingList<Thing> stuff = new BindingList<Thing>();
            stuff.Add(new Thing("One", "Two"));
            stuff.Add(new Thing("Filter", "Two"));
            stuff.Add(new Thing("Three", "Four"));
 
            radGridView1.DataSource = stuff;
        }
 
        private void radGridView1_CustomFiltering(object sender, Telerik.WinControls.UI.GridViewCustomFilteringEventArgs e)
        {
            if ((e.Row.DataBoundItem as Thing).Value1 == "Filter")
            {
                e.Visible = false;
            }
            e.Handled = !e.Visible;
        }
    }
 
    public class Thing
    {
        public string Value1 { get; set; }
        public string Value2 { get; set; }
 
        public Thing(string val1, string val2)
        {
            Value1 = val1;
            Value2 = val2;
        }
    }

4 Answers, 1 is accepted

Sort by
0
Accepted
Ivan Petrov
Telerik team
answered on 26 Jun 2013, 02:57 PM
Hello Randy,

Thank you for writing.

Thanks to your code I was able to quickly reproduce the issue. I can confirm that it is an issue in the filtering mechanism of RadGridView and I have logged it in our Public Issue Tracking System - PITS. You can track its progress, subscribe for status changes and add your vote/comment to it on the following link - PITS Issue. To workaround the issue you can remove the filtering when the user deletes the text inside the filter cell. Here is how to achieve that:
this.radGridView1.ValueChanging += radGridView1_ValueChanging;
 
private void radGridView1_ValueChanging(object sender, ValueChangingEventArgs e)
{
    if (this.radGridView1.CurrentColumn.Name == "Value1" && Convert.ToString(e.NewValue) == String.Empty)
    {
        int i = 0;
 
        while (i < this.radGridView1.FilterDescriptors.Count)
        {
            if (this.radGridView1.FilterDescriptors[i].PropertyName == "Value1")
            {
                this.radGridView1.FilterDescriptors.RemoveAt(i);
                continue;
            }
 
            i++;
        }
    }
}

I have also updated your Telerik Points for bringing this issue to our attention.

I hope this will be useful. Should you have further questions, I would be glad to help.

Regards,
Ivan Petrov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Randy
Top achievements
Rank 1
answered on 27 Jun 2013, 11:54 AM
Thank you for the response.  Your answer did fix the issue, however I went with a slightly more generic approach.

private void grid_ValueChanging(object sender, ValueChangingEventArgs e)
        {
            if (grid.CurrentRow is GridViewFilteringRowInfo && Convert.ToString(e.NewValue) == String.Empty)
            {
                int i = 0;
 
                while (i < grid.FilterDescriptors.Count)
                {
                    if (grid.FilterDescriptors[i].PropertyName == grid.CurrentColumn.Name)
                    {
                        grid.FilterDescriptors.RemoveAt(i);
                        continue;
                    }
 
                    i++;
                }
            }
        }
0
Mateusz
Top achievements
Rank 1
answered on 19 Jul 2013, 12:01 PM
Hi there, 

I do not want to create a new topic, as my problem is similar to your's. 

If I create a DataSet and fill it with data using the following SQL query:

SELECT 'Something' AS Name
UNION ALL
SELECT 'Something'
UNION ALL
SELECT 'Something2'
UNION ALL
SELECT ''
UNION ALL
SELECT ''

it is impossible to filer (with filter box's "not equal to" or "equal to" options) "empty" values in order to see <> '' or = '' records.
However, if you click the filter box, type anything in,erase it and then click on filter image to choose "equal to" or "not equal to" options, values will be filtered perfectly. 
The question is, if it is possible to filter it without typing and erasing values ? What value is stored in filter's text box by default, that it is impossible to filter it properly at the beginning?

Thanks in advance.

Regards,
Mateusz
0
Ivan Petrov
Telerik team
answered on 24 Jul 2013, 02:38 PM
Hi Mateusz,

Thank you for writing.

Initially when the grid is shown the filter descriptors collection of RadGridView is empty. When you input a letter in the filter text field a new filter descriptor is created. From that point on when you continue to type letters or you delete the text the value of this filter descriptor is updated. When you delete the text the value of the filter is an empty string. You can set this as the initial value for the filter by adding a FilterDescriptor with this value.

I hope this will be useful. Feel free to write back with further questions.

Regards,
Ivan Petrov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
Randy
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
Randy
Top achievements
Rank 1
Mateusz
Top achievements
Rank 1
Share this question
or