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

Column sized event

1 Answer 39 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Vincent
Top achievements
Rank 1
Vincent asked on 13 Oct 2011, 03:47 PM
EDIT: I posted in the wrong forum. Could someone move this to the *Silverlight* GridView forum? Thanks

Hi,

I have a grid with dynamically created columns whose Width are set to GridViewLength.SizeToCells.
When the databinding is completed, columns resize themselves according to their content.

I'd like to make sure that no column, by default (ie. on first display), has a width greater than the width of my grid (minus 50 pixels for example). But I don't want to set the MaxWidth: the user must be able to enlarge the column if he or she wishes to.

I tried to change the width in the Grid_LayoutUpdated event, but it's too early: columns don't have their width / desiredwidth / actualwidth calculated yet (at that time, it seems the width is based on the header width only).
Same thing with Grid_Loaded. Too early.

Is there an event on which I can perform this kind of piece of code?

private void Grid_????Event(object sender, System.EventArgs e)
{
    var maxSize = Grid.ActualWidth - 10;
    if (maxSize <= 50) // the grid is too small to adjust sizes
        return;
    // make sure that no column is larger than the grid
    foreach (var column in Grid.Columns)
        column.Width = Math.Min(maxSize, column.Width.DisplayValue);
}

Or is there another way to achieve this?

Thanks

1 Answer, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 17 Oct 2011, 08:58 AM
Hi Vincent,

You can try to work with ColumnWidthChanging/ColumnWidthChanged events. 
 

Greetings,
Maya
the Telerik team

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

Tags
GridView
Asked by
Vincent
Top achievements
Rank 1
Answers by
Maya
Telerik team
Share this question
or