Hiding Available Filters in Excel Like Filtering

6 posts, 0 answers
  1. Georg
    Georg avatar
    4 posts
    Member since:
    Jul 2011

    Posted 18 Jul 2011 Link to this post

    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
  2. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 21 Jul 2011 Link to this post

    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!

  3. webmaster
    webmaster avatar
    2 posts
    Member since:
    Mar 2011

    Posted 25 Nov 2011 Link to this post

    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
  4. Svett
    Admin
    Svett avatar
    728 posts

    Posted 28 Nov 2011 Link to this post

    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.

  5. Peter Bogoyavlensky
    Peter Bogoyavlensky avatar
    20 posts
    Member since:
    Feb 2009

    Posted 29 Jan 2014 Link to this post

    How can I do it in version 2013.2.724.20 ?

    I suppose that there is no *CreateFilteringDropDownMenu* method anymore.
  6. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3469 posts

    Posted 03 Feb 2014 Link to this post

    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 >>
Back to Top