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

Hide Filter Box in Filter Row

3 Answers 275 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Argos
Top achievements
Rank 1
Argos asked on 02 Dec 2013, 09:32 AM
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!

3 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 03 Dec 2013, 11:35 AM
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 >>
0
Argos
Top achievements
Rank 1
answered on 05 Dec 2013, 10:11 AM
Hi Denislava,

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

regards

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 09 Dec 2013, 06:05 PM
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 >>
Tags
GridView
Asked by
Argos
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Argos
Top achievements
Rank 1
Share this question
or