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

Hiding Available Filters in Excel Like Filtering

5 Answers 162 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Georg
Top achievements
Rank 1
Georg asked on 18 Jul 2011, 01:51 PM
Hi,

I have a problem with GridView and Filtering. There is a submenu showing all available filters such as ("Contains", "Does not contain", "Starts with", etc.). Now I want to hide some of those entries for specific columns. I haven't found any examples solving my problem. Could anyone give me a hint or provide me some short example solving my problem?

Thx

5 Answers, 1 is accepted

Sort by
0
Martin Vasilev
Telerik team
answered on 21 Jul 2011, 08:26 AM
Hello Georg,

Thank you for writing.

You can customize the context menu of the Excel-like filtering by using a custom header cell element and overriding the CreateFilteringDropDownMenu method. This will give you access to the menu items. Please consider the following code as an example:
{
     void radGridView1_CreateCell(object sender, GridViewCreateCellEventArgs e)
     {
         if (e.CellType == typeof(GridHeaderCellElement))
         {
             e.CellType = typeof(CustomHeaderCellElement);
         }
     }
 }
 
 public class CustomHeaderCellElement : GridHeaderCellElement
 {
     public CustomHeaderCellElement(GridViewColumn column, GridRowElement row) : base(column, row) { }
 
     protected override Type ThemeEffectiveType
     {
         get
         {
             return typeof(GridHeaderCellElement);
         }
     }
 
     protected override RadSizableDropDownMenu CreateFilteringDropDownMenu()
     {
         RadSizableDropDownMenu menu = base.CreateFilteringDropDownMenu();
         ((RadMenuItem)menu.Items[1]).Items[0].Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
 
         return menu;
     }
 }

Hope this helps. Let me know if you have any additional questions.
 
Kind regards,
Martin Vasilev
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
webmaster
Top achievements
Rank 1
answered on 25 Nov 2011, 04:25 PM
I have a problem, I used the recommendation but I get the following error message

 'Telerik.WinControls.UI.GridHeaderCellElement' no contiene una definición para 'CreateFilteringDropDownMenu' 

I have the Q1 version

how I can fix it.
thanks
0
Svett
Telerik team
answered on 28 Nov 2011, 04:34 PM
Hello Webmaster,

The only way to use the supplied code snippet is by upgrading to the latest version Q3 2011 (2011.3.11.1116). In the version that you are using this approach is not available due to limited extensibility of this functionality. There is no other alternative to accomplish the desired scenario.

Greetings,
Svett
the Telerik team

Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.

0
Peter Bogoyavlensky
Top achievements
Rank 1
answered on 30 Jan 2014, 05:20 AM
How can I do it in version 2013.2.724.20 ?

I suppose that there is no *CreateFilteringDropDownMenu* method anymore.
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 03 Feb 2014, 01:39 PM
Hello Peter,

Thank you for contacting Telerik Support.

In order to hide certain filter options in the Excel-like filtering pop up, using the specified version (2013.2.724) please have a look at the following code snippet:
public Form1()
{
    InitializeComponent();
    this.radGridView1.CreateCell += radGridView1_CreateCell;
}
 
private void radGridView1_CreateCell(object sender, GridViewCreateCellEventArgs e)
{
    if (e.CellType == typeof(GridHeaderCellElement))
    {
        e.CellType = typeof(CustomHeaderCellElement);
    }
}
 
private void Form1_Load(object sender, EventArgs e)
{
    this.productsTableAdapter.Fill(this.northwindDataSet.Products);
 
    this.radGridView1.EnableFiltering = true;
    this.radGridView1.MasterTemplate.ShowHeaderCellButtons = true;
    this.radGridView1.MasterTemplate.ShowFilteringRow = false;
}
 
public class CustomHeaderCellElement : GridHeaderCellElement
{
    public CustomHeaderCellElement(GridViewColumn column, GridRowElement row) : base(column, row)
    {
    }
 
    protected override Type ThemeEffectiveType
    {
        get
        {
            return typeof(GridHeaderCellElement);
        }
    }
 
    protected override IGridFilterPopup CreateFilterPopup()
    {
        RadListFilterPopup popup = base.CreateFilterPopup() as RadListFilterPopup;
        ((RadMenuItem)popup.Items[1]).Items[0].Visibility = ElementVisibility.Collapsed;
        return popup;
    }
}

However, I would recommend you a simpler approach using the FilterPopupInitialized event: 
private void radGridView1_FilterPopupInitialized(object sender, FilterPopupInitializedEventArgs e)
{
    RadListFilterPopup popup = e.FilterPopup as RadListFilterPopup;
    ((RadMenuItem)popup.Items[1]).Items[0].Visibility = ElementVisibility.Collapsed;
}

I hope this information helps. Should you have further questions, I would be glad to help.

Regards,
Desislava
Telerik
TRY TELERIK'S NEWEST PRODUCT - 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
Georg
Top achievements
Rank 1
Answers by
Martin Vasilev
Telerik team
webmaster
Top achievements
Rank 1
Svett
Telerik team
Peter Bogoyavlensky
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or