Resize Radgridview to fit the Columns width after datasource being updated

2 Answers 160 Views
GridView
mansouri
Top achievements
Rank 1
Iron
mansouri asked on 06 May 2022, 02:15 PM
after the data source for the grid is being updated the columns adjusts them widths perfectly by using "BestFitColumns(BestFitColumnMode.DisplayedCells)" ,but what i wan to acheive next is to resize the hole grid based on the new size of the columns , i have set the autosize property to true and also tried AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill but that stops the columns to adjust based on the text inside , can't i adjust both together columns and hole grid width ?? 

2 Answers, 1 is accepted

Sort by
0
tar
Top achievements
Rank 2
Iron
Iron
Iron
answered on 06 May 2022, 02:38 PM

If you set AutoSizeColumnsMode to GridViewAutoSizeColumnsMode.Fill, the grid will be restricted to the size of its parent control it is put into (e.g. a Panel). Therefore, you can only adjust the columns width inside the restricted grid size by looping through all columns and calling column.BestFit().

To adjust the size of the grid itself, you need to set AutoSizeColumnsMode to GridViewAutoSizeColumnsMode.None whereby a horizontal scrollbar will appear if the grid size will get larger than its parent control.

mansouri
Top achievements
Rank 1
Iron
commented on 06 May 2022, 03:33 PM

i looped through the columns and did a bestfit but it adjusted the size based on the header text not the actual rows content 
tar
Top achievements
Rank 2
Iron
Iron
Iron
commented on 06 May 2022, 03:56 PM

Could you try BestFitColumnMode.AllCells?
0
Dinko | Tech Support Engineer
Telerik team
answered on 09 May 2022, 07:33 AM

Hello mansouri,

As M S mentioned, you can try using the BestFitColumns() method and pass BestFitColumnMode.AllCells enumeration as parameter. You could check the Resizing columns programmatically help article for more information regarding this method. 

Regards,
Dinko
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
GridView
Asked by
mansouri
Top achievements
Rank 1
Iron
Answers by
tar
Top achievements
Rank 2
Iron
Iron
Iron
Dinko | Tech Support Engineer
Telerik team
Share this question
or