Change width of Textbox of SearchPanel in RadGridView

1 Answer 122 Views
GridView
Magdalena
Top achievements
Rank 1
Magdalena asked on 28 Oct 2021, 02:07 PM

Hi!

I need a wider SearchPanel Textbox. Changing the Width of SearchPanel didn't change the width of the TexBox within.

I tried to access it this way in Code behind but the result is always null:

https://www.telerik.com/forums/select-searchasyoutype-on-startup

 

Could anyone help me to achieve this?

Thank you!

1 Answer, 1 is accepted

Sort by
0
Stenly
Telerik team
answered on 02 Nov 2021, 12:43 PM

Hello Magdalena,

In order to change the width of the TextBox element, you would need to follow the approach proposed by my colleague in the forum thread. The use of the ChildrenOfType extension method, in the Loaded event of the grid view, returns the needed element.

private void gridView_Loaded(object sender, RoutedEventArgs e)
{
    var gridView = (RadGridView)sender;

    var textbox = gridView.ChildrenOfType<TextBox>().FirstOrDefault(x => x.Name == "PART_SearchAsYouTypeTextBox");

    textbox.MaxWidth = 500;
    textbox.Width = 450;
}

Note that if you use NoXaml dlls and the theme resources are not merged, the ChildrenOfType method won't return anything. Also, in order for the method to work properly the ShowSearchPanel property of RadGridView should be set to True initially.

Another approach you could take is to extract the default control template and modify the TextBox element with Name="PART_SearchAsYouTypeTextBox". The needed control template has Name="GridViewSearchPanelTemplate", and after modifying it, create a new style targeting telerik:GridViewSearchPanel, and set the changed control template to the Template property.

That said, I have prepared a sample project, that has both of these approaches' implementation. Also, for the second approach, the Office_Black theme's control template has been extracted. If any other theme is used, the corresponding template would need to be extracted.

Regards,
Stenly
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Magdalena
Top achievements
Rank 1
commented on 15 Nov 2021, 03:28 PM

Hi Stenly,

thank you so much for your answer, it was very helpful!

Best regards,

Magdalena

Tags
GridView
Asked by
Magdalena
Top achievements
Rank 1
Answers by
Stenly
Telerik team
Share this question
or