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

Add extra button to the SearchRow in GridView

1 Answer 139 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sameh
Top achievements
Rank 1
Sameh asked on 08 Oct 2018, 06:54 PM

Hi, 

 

Is there any way to add new control (radbutton for instance) in the SearchRow? next to the gear button for example?

 

Many thanks

Sameh.

1 Answer, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 09 Oct 2018, 08:01 AM
Hello Sameh,

Thank you for writing.

You can create a custom cell and use it with the search row, similarly as demonstrated here: https://docs.telerik.com/devtools/winforms/gridview/cells/creating-custom-cells. Please check my code snippet below: 
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
 
        this.radGridView1.CreateCell += radGridView1_CreateCell;
 
        this.radGridView1.DataSource = this.GetData();
        this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
        this.radGridView1.AllowSearchRow = true;
    }
 
    private void radGridView1_CreateCell(object sender, GridViewCreateCellEventArgs e)
    {
        if (e.CellType == typeof(GridSearchCellElement))
        {
            e.CellType = typeof(MyGridSearchCellElement);
        }
    }
 
    private DataTable GetData()
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("Id", typeof(int));
        dt.Columns.Add("Name", typeof(string));
        dt.Columns.Add("Date", typeof(DateTime));
        dt.Columns.Add("Bool", typeof(bool));
        dt.Columns.Add("Description", typeof(string));
        for (int i = 0; i < 2000; i++)
        {
            for (int j = 0; j < 5; j++)
            {
                dt.Rows.Add(i, "Name " + j, DateTime.Now.AddDays(i), i % 2 == 0 ? true : false, "Description " + i);
            }
        }
 
        return dt;
    }
}
 
public class MyGridSearchCellElement : GridSearchCellElement
{
    private RadButtonElement button;
 
    public MyGridSearchCellElement(GridViewColumn column, GridRowElement row)
        : base(column, row)
    { }
 
    protected override void CreateChildElements()
    {
        base.CreateChildElements();
 
        this.button = new RadButtonElement();
        this.button.Text = "Button!";
        this.Children.Add(this.button);
    }
 
    protected override SizeF ArrangeOverride(SizeF finalSize)
    {
        SizeF s = base.ArrangeOverride(finalSize);
        RectangleF rect = new RectangleF(this.OptionsButton.BoundingRectangle.X + this.OptionsButton.BoundingRectangle.Width + this.FindNextButton.Margin.Right + this.OptionsButton.Margin.Left, this.OptionsButton.BoundingRectangle.Y, this.button.DesiredSize.Width, this.OptionsButton.BoundingRectangle.Height);
        this.button.Arrange(rect);
 
        return s;
    }
}

I am also attaching a screenshot showing the result on my end. I hope this will help.

Regards,
Hristo
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Devel
Top achievements
Rank 1
commented on 08 Sep 2023, 07:00 AM

Hello, can be this done from XAML only to have support for bindings? If not can it be created as feature request?

Thanks.

Dinko | Tech Support Engineer
Telerik team
commented on 08 Sep 2023, 01:22 PM

The scenario which is discussed in this thread is related to RadGridView for WinForms. You can check the Telerik UI for WPF Forum for a similar thread. If such is not found, you can create a new forum thread with your questions inside.
Tags
GridView
Asked by
Sameh
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Share this question
or