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

Shrink Column Width

1 Answer 117 Views
GridView
This is a migrated thread and some comments may be shown as answers.
David Romanchuk
Top achievements
Rank 1
David Romanchuk asked on 05 Jan 2010, 07:47 PM
Hello,

The column of my grid is set to SizeToContent, which of course causes my column size to increase to the size of the lengthiest data in the column, which is great. When the row is removed, however, the column remains at that extended size. I would like to be able to have my column automatically "snap back" to the next lengthiest bit of data remaining in the grid, but have been unable to find a way to accomplish this with any of the existing properties. Is there a way to accomplish this kind of behaviour I'm missing?

Thanks,

Dave

1 Answer, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 08 Jan 2010, 01:27 PM
Hello David Romanchuk,

There is not a direct property but there is a solution to the problem.
After you change the source collection ( e.g. remove an item ) , you should set the width of the column to any value and then revert it to Auto. Reverting to Auto will force the column to recalculate the auto-fit width.

the code may look something like :

this.RadGirdView1.Columns[0].Width = new GridViewLength(1);

this.RadGirdView1.Columns[0].Width = GridViewLength.Auto;


For example if you may place such calls in the CollectionChanged event of your source collection. This way each time an item is removed, the column will be forced to recalculate the auto-fit-width.

Greetings,
Pavel Pavlov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
David Romanchuk
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Share this question
or