Auto adjust GridView columns width ?

1 Answer 367 Views
GridView
Romain
Top achievements
Rank 2
Iron
Iron
Romain asked on 24 Mar 2023, 02:09 PM

Hi,

I'm working with a GridView where some Editing cells are a lot wider than the Cell. The GridView resize correctly to fit the editing mode but doesn't resize correctly when edit is completed.

I tried to set the Column Width to Auto, in the GridView and individually in each column, but the calculation for optimal width seems to be chaotic and triggered but some other actions on the GridView.

Is there a way in code behind to iterate through each column and trigger a width calculation?

 

Thank you for your help

1 Answer, 1 is accepted

Sort by
0
Vladimir Stoyanov
Telerik team
answered on 28 Mar 2023, 11:47 AM

Hello Romain,

The desired behavior (of the column resizing when it is edited and resizing back when the edit ends) should be the default for the control. I tested this scenario in a sample project, where I defined a CellEditTemplate with a larger Width and on my end the column is resized as expected. 

I am attaching the sample project, which I used for testing purposes. Can you check it out and see how it differs from the setup on your end? Should you need any further assistance, you can modify the provided project in order to demonstrate the scenario and send it back. This will hopefully allow me to investigate further and better assist you. 

Thank you in advance for any help you can provide.

Regards,
Vladimir Stoyanov
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/.

Romain
Top achievements
Rank 2
Iron
Iron
commented on 28 Mar 2023, 07:49 PM

I agreed with you, in most case it works pretty good... But in my case, I have more a more complex implementation with template selectors, style selectors, and validations.

Unfortunately, it would be way too time consuming to recreate an example project that reflects my projects and its architecture.

My original question is: is there a way, in code behind, to go through each columns and force it to re-calculate it's size ? There is something for WinForms libraries and so, I was hoping to find a solution for WPF

 

Thank you

 

Vladimir Stoyanov
Telerik team
commented on 30 Mar 2023, 11:56 AM

What comes to mind in order to force the columns to update is to set their Width to a fixed size and then set it back to Auto. Here is how that might look:

foreach (var c in this.gridView.Columns)
{
                c.Width = new GridViewLength(100, Telerik.Windows.Controls.GridViewLengthUnitType.Pixel);
                c.Width = GridViewLength.Auto;
}

Do give this a try and let me know, if it helps. 

Tags
GridView
Asked by
Romain
Top achievements
Rank 2
Iron
Iron
Answers by
Vladimir Stoyanov
Telerik team
Share this question
or