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

Programmatically add filters then disable user from changing

2 Answers 96 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Shaun
Top achievements
Rank 1
Shaun asked on 26 Apr 2013, 01:47 AM
Hi,

I'm using a Gridview which I filter programmatically based on input from another control, this works well.
But is it possible to prevent the user from doing their own filtering on the same grid, I still want to show the column headers just want to remove the filter icon and or functionality.

Cheers
Shaun

2 Answers, 1 is accepted

Sort by
0
Anton
Telerik team
answered on 30 Apr 2013, 11:35 AM
Hello Shaun,

Thank you for writing.

There are two ways to hide the filter buttons in header cells:
1. You can set ShowHeaderCellButtons property of MasterTemplate:
this.radGridView1.MasterTemplate.ShowHeaderCellButtons = false;

2. Through the ViewCellFormating event of RadGridView

Note that if you are using Filtering Row you can hide its filter buttons only through the ViewCellFormating event of RadGridView. For example:
void radGridView1_ViewCellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
    //Hidding buttons in headers
    if (e.CellElement is GridHeaderCellElement)
    {
        e.CellElement.Children[0].Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
    }
 
    //Hidding buttons in Filtering Row
    if (e.CellElement is GridFilterCellElement)
    {
        GridFilterButtonElement button = e.CellElement.Children[0] as GridFilterButtonElement;
        if (button != null)
        {
            foreach (RadElement item in button.Children)
            {
                item.Visibility = ElementVisibility.Collapsed;
            }
        }
    }
}

Attached is demo project that comprises the code above.

I hope this helps. Let me know if you have any additional questions.

Regards,
Anton
the Telerik team
WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
0
Shaun
Top achievements
Rank 1
answered on 05 May 2013, 11:06 PM
Hi Anton,

Thanks for that, works a treat.

Cheers

Shaun
Tags
GridView
Asked by
Shaun
Top achievements
Rank 1
Answers by
Anton
Telerik team
Shaun
Top achievements
Rank 1
Share this question
or