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

How do you make the columns fill the grid area proportionaly ?

13 Answers 2374 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Michel
Top achievements
Rank 1
Michel asked on 29 Jul 2011, 10:25 PM
How do you make the columns fill the grid area proportionaly ?

I want columns to also stretch proprotionaly when you resixze the grid...

Thanks,

13 Answers, 1 is accepted

Sort by
0
Vanya Pavlova
Telerik team
answered on 30 Jul 2011, 08:16 AM
Hi Michel,

 
Why not set the ColumnWidth property of RadGridView to star ("*")?  You may achieve the same effect through setting the Width of the last column to star.


All the best,
Vanya Pavlova
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Michel
Top achievements
Rank 1
answered on 01 Aug 2011, 01:36 PM
Because, as stated in my post, I want all columns to resize proportionaly, not just the last column.

I would also like to have "some" columns with a fixed width...

0
Vanya Pavlova
Telerik team
answered on 01 Aug 2011, 03:44 PM
Hello Michel,

 
Let me try to explain how the ColumnWidth property works in RadGridView.
You may set this property to the following values:


Auto - Automatically fits the size according to content
Fill - Star ("*") - Fills the available space
SizeToHeader - Column width is equal to the width of the header cell
SizeToCells - Column width is equal to the width of the widest (excluding header) cell
# pixels - Sets fixed column width size


Since you have set a fixed witdh for the columns in RadGridView, they would not fit the available space. 
I recommend you to use the sizing to achieve the desired result. 


Best wishes,
Vanya Pavlova
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Michel
Top achievements
Rank 1
answered on 01 Aug 2011, 05:55 PM
Thanks, I will try this if that's the only way.
0
Michel
Top achievements
Rank 1
answered on 22 Aug 2011, 07:15 PM
Hello,

I still experience a problem with column sizes...

I have set a default style MinWidth="100" which applies to all columns.

I set for some columns the Width="*" which works fine, these columns are now auto-stretch/auto-resize to fill the resizable client area.

<DockPanel>
    <
GridView>
        <GridViewColumn Header="Stretch" 
Width="*" />
        <GridViewColumn Header="Fixed" 
MinWidth="100" />
        <GridViewColumn 
Header="Stretch" Width="*" />
    </GridView>
</DockPanel>

But, at runtime, I can only make the auto-stretch columns larger not smaller...

There must be something else I forget !


0
Vanya Pavlova
Telerik team
answered on 23 Aug 2011, 10:32 AM
Hello Michel,


Indeed a single star size column cannot be increased/decreased and the behavior is by design. The general approach is to add an additional star size column and then you will be able to resize these columns, please refer to the attached picture. However I am a bit confused by the snippet provided, because everything works fine by my side. The couple of star size columns can be resized and the column between these cannot me smaller than 100 px.  


May you please elaborate a bit more about your exact settings? 


Greetings,
Vanya Pavlova
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Michel
Top achievements
Rank 1
answered on 23 Aug 2011, 01:42 PM
Ok, thanks.

Your reply "Indeed a single star size column cannot be increased/decreased and the behavior is by design." explains the behavior.

Like I mentionned I "can" resize the column, but I can only make it larger, not smaller.

So I guess I can only use the "star" parameter on the rightmost column...

Thanks,

Michel

0
Kelly
Top achievements
Rank 1
answered on 03 Oct 2011, 10:39 PM
Hi,

I am having an issue.  My columns won't open all the way and I have ColumnWidth property of RadGridView to star ("*").  I am displaying about 80 fields.

Regards,

Kelly
0
Jorge
Top achievements
Rank 1
answered on 26 Dec 2012, 10:02 PM
How do you accomplish this without XAML, in code behind?
Thanks.
0
hart
Top achievements
Rank 1
Veteran
answered on 24 Oct 2013, 01:42 PM

How do you do this via Code Behind..

I create my RadDataGrids on the fly in codebehind.  This "star" code is Read Only and this does not work

myGrid.Columns[myGrid.Columns.Count - 1].Width.IsStar = true;

Thanks, HH

0
Matt
Top achievements
Rank 1
answered on 24 Oct 2013, 05:11 PM
You could create a custom behavior for the RadGridViewColumnSizeChanged (or changing whatever you prefer) which would adjust a property value to the new width and then bind all your column widths to that property?

Something like this:
private static void OnColumnWidthChanged(object sender, ColumnWidthChangedEventArgs args)
        {
            RadGridView grid= sender as RadGridView;
             
            Telerik.Windows.Controls.GridViewColumn gvc = args.Column;
             
            if (grid != null)
            {
                var rows = grid.ChildrenOfType<GridViewRow>();
                 
                foreach (GridViewRowItem rowItem in rows)
                {
                    foreach (GridViewCell cell in rowItem.Cells)
                    {
                            cell.Column.SetBinding(GridViewColumn.WidthProperty, new Binding("ActualWidth")
                            {
                                Source = gvc
                            });
                        }
                    }
                }
            }
        }


Then they will all either adjust once the resize has completed or during the event accordingly.  Something like that like I said inside an attached behavior if you are all MVVM else if you are in the code behind just handle the event there if you do not care about MVVM as much, though in theory this is still ok even in MVVM because it is UI update only.
0
Rob
Top achievements
Rank 1
answered on 30 Jan 2017, 09:25 AM
myGrid.Columns[myGrid.Columns.Count - 1].Width = new GridViewLength(1, GridViewLengthUnitType.Star);
0
Janitha
Top achievements
Rank 1
answered on 21 Mar 2018, 09:03 AM

Click the small white arrow on the right side of the grid view and select edit columns

Then click the AutoSizemode under the Layout property and select "Fill"

Tags
GridView
Asked by
Michel
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
Michel
Top achievements
Rank 1
Kelly
Top achievements
Rank 1
Jorge
Top achievements
Rank 1
hart
Top achievements
Rank 1
Veteran
Matt
Top achievements
Rank 1
Rob
Top achievements
Rank 1
Janitha
Top achievements
Rank 1
Share this question
or