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

Add Current Selection to Filter

3 Answers 116 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Gholi
Top achievements
Rank 1
Gholi asked on 18 Jun 2016, 06:10 AM
In Microsoft Excel there is an option named Add Current Selection to Filter. Actually, in Excel, when you search a key in filter popup and click OK, then when you search another key in filter popup then there is an option named 'Add Current Selection to Filter'. I need something like this option in radGridView Excel Like Filtering. Please see the attached file.

3 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 20 Jun 2016, 08:25 AM
Hello ,

Thank you for writing.

This is currently not supported out of the box. We will consider to implement it if we receive more requests for it. 

What you can do is to manually add this item to the tree view and handle the case when it is checked. The following snippet shows how you can access the elements of the filter popup:
private void RadGridView1_FilterPopupInitialized(object sender, FilterPopupInitializedEventArgs e)
{
    RadListFilterPopup popup = e.FilterPopup as RadListFilterPopup;
    if (popup != null)
    {
        popup.MenuTreeElement.TreeView.Nodes.Add("Add Current Selection to Filter");
        popup.MenuTreeElement.TreeView.NodeCheckedChanged += TreeView_NodeCheckedChanged;
        popup.TextBoxMenuItem.TextBox.TextChanged += TextBoxMenuItem_TextChanged;
    }
}
 
private void TextBoxMenuItem_TextChanged(object sender, EventArgs e)
{
     
}
 
private void TreeView_NodeCheckedChanged(object sender, TreeNodeCheckedEventArgs e)
{
    if (e.Node.Text == "Add Current Selection to Filter")
    {
        if (e.Node.Checked)
        {
 
        }
    }
}

Let me know if I can assist you further.

Regards,
Dimitar
Telerik
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
0
Gholi
Top achievements
Rank 1
answered on 22 Jun 2016, 05:35 AM
I don't know what I should do in TextBoxMenuItem_TextChanged and TreeView_NodeCheckedChanged events so that it behaves like Microsoft Excel. Please help me. Thank you again.
0
Accepted
Dimitar
Telerik team
answered on 22 Jun 2016, 09:58 AM
Hi ,

Thank you for writing back.

I have created a sample implementation for this. I used a button instead of a node because the tree view filters the nodes when you are typing in the text box and there is no way to insert the node at this point:
private void RadGridView1_FilterPopupInitialized(object sender, FilterPopupInitializedEventArgs e)
{
    RadListFilterPopup popup = e.FilterPopup as RadListFilterPopup;
    if (popup != null)
    {
        var button = new RadButtonElement();
        button.Text = "add to filter";
        button.Click += Button_Click;
 
        button.Enabled = false;
        button.Margin = new Padding(0, 0, 7, 0);
 
        popup.ButtonsMenuItem.Children[0].Children.Insert(0, button);
 
        popup.TextBoxMenuItem.TextBox.TextChanged += TextBoxMenuItem_TextChanged;
    }
}
 
private void Button_Click(object sender, EventArgs e)
{
    var button = (RadButtonElement)sender;
    var popup = button.ElementTree.Control as RadListFilterPopup;
 
    string selcted = "";
 
    var filter = radGridView1.FilterDescriptors[0] as CompositeFilterDescriptor;
 
    if (filter != null)
    {
        foreach (var item in popup.MenuTreeElement.TreeView.Nodes[0].Nodes)
        {
            if (item.Checked)
            {
                FilterDescriptor newFilter = new FilterDescriptor(filter.PropertyName, FilterOperator.IsEqualTo, item.Text);
             
                filter.FilterDescriptors.Add(newFilter);
            }
        }
    }
 
    popup.ClosePopup(new PopupCloseInfo(RadPopupCloseReason.CloseCalled, null));
}
 
private void TextBoxMenuItem_TextChanged(object sender, EventArgs e)
{
    var textBox = (RadTextBox)sender;
    var popup = textBox.Parent as RadListFilterPopup;
    var button = popup.ButtonsMenuItem.Children[0].Children[0];
 
    if (textBox.Text != "")
    {
        button.Enabled = true;
    }
    else
    {
        button.Enabled = false;
    }
}

I hope this will be useful. 

Regards,
Dimitar
Telerik
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
Tags
GridView
Asked by
Gholi
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Gholi
Top achievements
Rank 1
Share this question
or