Hide Filter Box in Filter Row

4 posts, 0 answers
  1. Argos
    Argos avatar
    6 posts
    Member since:
    Aug 2012

    Posted 02 Dec 2013 Link to this post

    Hi,

    I need to have FilterRow to filter some columns. But I need also to filter two columns by checkboxes out of the grid (toogle checkboxes add / remove filter descriptor for this columns). That's why I have to hide Filter Box for this two columns. I did it by ViewCellFormatting event:

    void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
    {
        GridFilterCellElement filterCell = e.CellElement as GridFilterCellElement;

        if (e.RowIndex == -1 && filterCell != null && filterCell.ColumnInfo.Name == "COLUMN_NAME")
        {
            filterCell.Visibility = Telerik.WinControls.ElementVisibility.Hidden;
        }
    }

    It works fine, but, as mentioned in documentation, significantly slow down rendering - especially for grid with 20 columns / 100000 rows with sorting.
    My question: is there any other solution?
    I tried:
    1) Attach / Detach this event - I tried to realize when cell with this filter box is redrawn ( because then by default it is again draw with filter box visible ). It speed up interacting with grid, but still there are situation when I see this filter box visible ( minimize Window, ColumnShooser Activate / Deactivate, DataBind, Click on filterRow ...) . Is it good way? Can I found and serve all situation in this way ?
    2) Use EditorRequired / Editor Initialized instead ViewCellFormatting. But It helps only not to display filter text box - filter description and button of dropdown list still are visible.

    void radGridView1_EditorRequired(object sender, EditorRequiredEventArgs e)
            {
                if (radGridView1.CurrentCell.ColumnInfo.Name == "COLUMN_NAME")
                {
                    e.Editor = null;
                    e.EditorType = null
                }
            }

    3) I was think about override GridViewTextBoxColumn - to find properties responsible for displaing filterbox but I can find such thing

    Could you give me some solution?

    Thanks in advance!
  2. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3945 posts

    Posted 03 Dec 2013 Link to this post

    Hello Adam,

    Thank you for contacting Telerik Support.

    Showing and hiding the filtering editor box for separate columns is not supported by RadGridView. The ViewCellFormatting event is appropriate to modify the non-data cells in the control. So, in order to hide the filtering cells for some columns, you can use the code snippet that you had provided. An alternative solution that I would recommend you to use is creating a custom GridFilterCellElement:
    private void Form1_Load(object sender, EventArgs e)
    {
        this.order_DetailsTableAdapter.Fill(this.nwindDataSet.Order_Details);
        radGridView1.EnableFiltering = true;
     
        radGridView1.CreateCell += radGridView1_CreateCell;
        radGridView1.CellBeginEdit += radGridView1_CellBeginEdit;
    }
     
    private void radGridView1_CellBeginEdit(object sender, GridViewCellCancelEventArgs e)
    {
        GridViewEditManager editManager = sender as GridViewEditManager;
        if (editManager.GridViewElement.CurrentCell is GridFilterCellElement && e.Column.Name == "ProductID")
        {
            e.Cancel = true;
        }
    }
     
    private void radGridView1_CreateCell(object sender, GridViewCreateCellEventArgs e)
    {
        if (e.CellType == typeof(GridFilterCellElement) && e.Column.Name == "ProductID")
        {
            e.CellElement = new CustomFilterCell((GridViewDataColumn)e.Column , e.Row);
        }
    }
     
    public class CustomFilterCell : GridFilterCellElement
    {
        public CustomFilterCell(GridViewDataColumn column, GridRowElement row) : base(column, row)
        {
        }
     
        protected override void CreateChildElements()
        {
            base.CreateChildElements();
            this.Children.Clear();
        }
    }

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

    Regards,
    Desislava
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC 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 >>
  3. Argos
    Argos avatar
    6 posts
    Member since:
    Aug 2012

    Posted 05 Dec 2013 Link to this post

    Hi Denislava,

    Thank you for your solution - custom GridFilterCellElement with CellBeginEdit and CreateCell events works faster than ViewCellFormatting event.

    regards

  4. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3945 posts

    Posted 09 Dec 2013 Link to this post

    Hello Adam,

    Thank you for writing back.

    CreateCell event fires when a new cell is going to be created only. ViewCellFormatting event is fired constrantly for all RadGridView cells in order to apply the necessary formatting settings. That is why this solution works faster.

    Please do not hesitate to contact us if you have any additional questions.

    Regards,
    Desislava
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC 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