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

How to auto size column with a resizeable header?

6 Answers 178 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 07 Nov 2014, 04:55 AM
How do I get my column widths to auto size, when the column header is resizeable?

e.g. I have a simple grid with a TextBox headers. As the user types into the box, the width increases. If text is removed from the box, the TextBox width decreases but the columns width remains the same. 

<telerik:RadGridView >
    <telerik:RadGridView.Columns>
        <telerik:GridViewColumn >
            <telerik:GridViewColumn.Header>
                <TextBox Text="Long texttttttttt" HorizontalAlignment="Left" />
            </telerik:GridViewColumn.Header>
        </telerik:GridViewColumn>
        <telerik:GridViewColumn Header="Star" Width="*" />
    </telerik:RadGridView.Columns>
</telerik:RadGridView>


In this example if you delete the long text, the width will not change. 
I had also tried changing the HeaderCellStyle to change its alignment/content alignment to left. This did not achieve the desired result of wanting the Star column to fill up the remaining space. 

The overall goal I am trying to achieve is to the standard headers with text boxes to allow for complex (server side) searching; this can not be achieved by filter row, custom filters only control the pop up which does not deliver an optimal user experience, foot search rows is also not optimal. 

6 Answers, 1 is accepted

Sort by
0
Alex
Top achievements
Rank 1
answered on 07 Nov 2014, 04:56 AM
I am using Telerik version:
2014.2.729.1050
0
Yoan
Telerik team
answered on 11 Nov 2014, 04:41 PM
Hello Alex,

I am afraid that there is no easy way for achieving this functionality. A possible solution would be to invoke GridView's UpdateLayout method when the TextBox is resized. Unfortunately, this will lead to performance degradation.

Regards,
Yoan
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Alex
Top achievements
Rank 1
answered on 12 Nov 2014, 03:56 AM
Hi Yoan,

I tried doing as you suggested, however, calling UpdateLayout did not result in the columns shrinking back down (It does not result in any visual change)

I've also discovered that this scenario can be very easily produced by using the out of the box RadGridView, and by typing into the FilterRow and then removing what you typed
0
Yoan
Telerik team
answered on 13 Nov 2014, 04:35 PM
Hello Alex,

You can try another approach - you can calculate the width of the TextBox in its SizeChanged event. Then you can set the Width of the column to be the calculated width. I have attached a sample project which demonstrates this approach.


Regards,
Yoan
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Alex
Top achievements
Rank 1
answered on 13 Nov 2014, 10:10 PM
I had tried this earlier but it did not achieve the desired result of GridViewLength.Auto ~like behaviour. 

I had set the GridViewColumn's width to the GridViewHeaderCell.DesiredSize.Width if it was less than the RenderSize.Width then I would revert it back to the previous width (Auto). This would make the column width shrink to the header size, but not to the cells size. 
0
Yoan
Telerik team
answered on 14 Nov 2014, 08:40 AM
Hi Alex,

I have already answered your other forum thread.

Regards,
Yoan
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
GridView
Asked by
Alex
Top achievements
Rank 1
Answers by
Alex
Top achievements
Rank 1
Yoan
Telerik team
Share this question
or