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

Hide Available Filters drop down

2 Answers 284 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Roger
Top achievements
Rank 1
Roger asked on 07 Nov 2014, 11:27 AM
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 Answers, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 12 Nov 2014, 09:31 AM
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.

 
0
Roger
Top achievements
Rank 1
answered on 13 Nov 2014, 02:28 AM
Thank you. Excellent stuff!

Roger
Tags
GridView
Asked by
Roger
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Roger
Top achievements
Rank 1
Share this question
or