Programmatically add filters then disable user from changing

3 posts, 0 answers
  1. Shaun
    Shaun avatar
    39 posts
    Member since:
    Sep 2012

    Posted 25 Apr 2013 Link to this post

    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. Anton
    Admin
    Anton avatar
    167 posts

    Posted 30 Apr 2013 Link to this post

    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.
  3. Shaun
    Shaun avatar
    39 posts
    Member since:
    Sep 2012

    Posted 05 May 2013 Link to this post

    Hi Anton,

    Thanks for that, works a treat.

    Cheers

    Shaun
Back to Top