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

FilterBar can the boxes to enter criteria not be hidden until clicked?

1 Answer 43 Views
GridView
This is a migrated thread and some comments may be shown as answers.
J
Top achievements
Rank 1
J asked on 21 Oct 2014, 05:44 PM
I want my users to be able to see that there is a spot to enter the criteria for the filter without having to know to click on the empty space and a box will appear. Is there a simple way to show those boxes to the users even when they do not have focus?

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 24 Oct 2014, 11:53 AM
Hi J,

Thank you for writing.

This can be achieved by creating a custom cell which contains a textbox:
public class MyFilterCell : GridFilterCellElement
{
    public MyFilterCell(GridViewDataColumn column, GridRowElement row) : base(column, row)
    {
    }
 
    RadTextBoxElement textbox;
     
    protected override void CreateChildElements()
    {
        base.CreateChildElements();
        textbox = new RadTextBoxElement();
        textbox.MinSize = new Size(50, 20);
        textbox.Alignment = ContentAlignment.MiddleCenter;
        textbox.TextChanged += textbox_TextChanged;
        this.Children.Add(textbox);
    }
     
    void textbox_TextChanged(object sender, EventArgs e)
    {
        this.Value = textbox.Text;
    }
     
    protected override SizeF ArrangeOverride(SizeF finalSize)
    {
        SizeF s = base.ArrangeOverride(finalSize);
        this.textbox.Arrange(new RectangleF(Children[1].DesiredSize.Width + 1, 3, 50,20));
        return s;
    }
    public override bool IsCompatible(GridViewColumn data, object context)
    {
        bool result =data is  GridViewDataColumn &&
               !(data is GridViewCheckBoxColumn) &&
               !(data is GridViewComboBoxColumn) &&
               !(data is GridViewDecimalColumn) &&
               !(data is GridViewDateTimeColumn) &&
               context is GridFilterRowElement;
 
        return result;
    }
 
}

The following code snippet shows how you can replace the default filter cell. In addition you can disable the showing of the editor for these cells:
void radGridView1_CellBeginEdit(object sender, GridViewCellCancelEventArgs e)
{
    if (e.Row is GridViewFilteringRowInfo && e.Column is GridViewTextBoxColumn)
    {
        e.Cancel = true;
    }
}
 
void radGridView1_CreateCell(object sender, GridViewCreateCellEventArgs e)
{
    if (e.CellType == typeof(GridFilterCellElement) && e.Column is GridViewTextBoxColumn)
    {
        e.CellElement = new MyFilterCell(e.Column as GridViewDataColumn, e.Row);
    }
}

I hope this helps.

Regards,
Dimitar
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.

 
Tags
GridView
Asked by
J
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or