Hide Available Filters drop down

3 posts, 1 answers
  1. Roger
    Roger avatar
    6 posts
    Member since:
    Jul 2012

    Posted 07 Nov 2014 Link to this post

    Hi Telerik,

    I'd like to be able to hide the Available Filters drop down list box for some GridView columns but not others when opening the Filter pop-up (Excel type filtering). Do you have some code I could use?

    I would also like to be able to change the font for the resultant (after selecting a menu item from the Available Filters list) Radgrid Filter dialog value entry fields, if possible.


    Thanks

    Roger
  2. Answer
    Dess
    Admin
    Dess avatar
    1601 posts

    Posted 12 Nov 2014 Link to this post

    Hello Roger,

    Thank you for writing.

    If I understand your requirement correctly, you are trying to hide the arrow button of the Available Filters item in the RadListFilterPopup. For this purpose, you should subscribe to the FilterPopupInitialized event and set the RadMenuItem.ShowArrow property to false for the desired column. Additionally, you should cancel the DropDownOpening event to prevent the drop down to show:
    public Form1()
    {
        InitializeComponent();
     
        this.radGridView1.EnableFiltering = true;
        this.radGridView1.ShowFilteringRow = false;
        this.radGridView1.ShowHeaderCellButtons = true;
     
        this.radGridView1.FilterPopupInitialized += radGridView1_FilterPopupInitialized;
    }

    private void radGridView1_FilterPopupInitialized(object sender, FilterPopupInitializedEventArgs e)
    {
        GridHeaderCellElement headerCell = sender as GridHeaderCellElement;
        RadListFilterPopup filterPopup = e.FilterPopup as RadListFilterPopup;
        if (headerCell != null && filterPopup != null)
        {
            if (headerCell.ColumnInfo.Name == "CustomerID")
            {
                RadMenuItem item = filterPopup.Items[1] as RadMenuItem;
                if (item != null)
                {
                    item.ShowArrow = false;
                    item.DropDownOpening -= item_DropDownOpening;
                    item.DropDownOpening += item_DropDownOpening;
                }
                else
                {
                    item.ShowArrow = true;
                    item.DropDownOpening -= item_DropDownOpening;
                }
            }
        }
    }
     
    private void item_DropDownOpening(object sender, CancelEventArgs e)
    {
        e.Cancel = true;
    }
     
    As to the question, related to changing the font, I suppose that you mean changing the CompositeFilterForm's font after selecting an item from the "Available Filters" menu. For this purpose, you should create a custom RadListFilterPopup and override its EditFilterDescriptor method. Afterwards, change the RadListFilterPopup with the custom one via the RadGridView.FilterPopupRequired event:
    private void radGridView1_FilterPopupRequired(object sender, FilterPopupRequiredEventArgs e)
    {
        e.FilterPopup = new CustomRadListFilterPopup(e.Column);
    }
     
    static Font font = new Font("Verdana", 10f, FontStyle.Italic);
     
    public class CustomRadListFilterPopup : RadListFilterPopup
    {
        public CustomRadListFilterPopup(GridViewDataColumn dataColumn) : base(dataColumn)
        {
        }
     
        protected override void EditFilterDescriptor(RadFilterComposeMenuItem menuItem)
        {
            RadFilterComposeMenuItem composeMenuItem = menuItem;
            string themeName = this.ThemeName;
     
            using (CompositeFilterForm filterForm = new CompositeFilterForm())
            {
                filterForm.Initialize(this.DataColumn, composeMenuItem.FilterDescriptor, true);
                filterForm.ThemeName = themeName;
                filterForm.Font = font;
                ChangeFont(filterForm.Controls);
                if (filterForm.ShowDialog() == DialogResult.Cancel)
                {
                    return;
                }
     
                FilterDescriptor descriptor = filterForm.FilterDescriptor;
                if (GridFilterCellElement.ValidateUserFilter(descriptor))
                {
                    this.FilterDescriptor = descriptor;
                    OnFilterConfirmed();
                }
            }
        }
     
        private void ChangeFont(ControlCollection controls)
        {
            foreach (Control c in controls)
            {
                c.Font = font;
                if (c.Controls.Count > 0)
                {
                    ChangeFont(c.Controls);
                }
            }
        }
    }

    It would be more appropriate to use a specific event instead of creating a custom RadListFilterPopup. I have logged a feature request in our feedback portal. You can track its progress, subscribe for status changes and add your vote/comment to it on the following link - feedback item.

    I have also updated your 
    Telerik points.

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

    Regards,
    Desislava
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Roger
    Roger avatar
    6 posts
    Member since:
    Jul 2012

    Posted 12 Nov 2014 in reply to Dess Link to this post

    Thank you. Excellent stuff!

    Roger
Back to Top