Column sized event

2 posts, 0 answers
  1. Vincent
    Vincent avatar
    2 posts
    Member since:
    Sep 2011

    Posted 13 Oct 2011 Link to this post

    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
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 17 Oct 2011 Link to this post

    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 >>

Back to Top