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

Resizing the gridview using total width of all visible columns

2 Answers 23 Views
GridView
This is a migrated thread and some comments may be shown as answers.
swarmttied
Top achievements
Rank 1
swarmttied asked on 25 Jan 2012, 12:14 AM
How exactly do I achieve this? I tried the snippet below but no luck at all. I always get a smaller value for the width.

        private void gridView_DataLoading(object sender, Telerik.Windows.Controls.GridView.GridViewDataLoadingEventArgs e)
        {
            double width = 0;
 
            foreach (var col in gridView.Columns)
            {
                // None of these gives me the desired value
                //width += col.ActualWidth;
                //width += col.Width.DisplayValue;
                //width += col.Width.Value;
            }
 
            gridView.Width = width;
        }

2 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 25 Jan 2012, 10:58 AM
Hello,

 Please try that approach:

private void clubsGrid_DataLoaded(object sender, EventArgs e)
        {
            clubsGrid.LayoutUpdated += new EventHandler(clubsGrid_LayoutUpdated);
        }
 
        void clubsGrid_LayoutUpdated(object sender, EventArgs e)
        {
            double width = 0;
 
            foreach (var col in clubsGrid.Columns)
            {
                width += col.ActualWidth;
            }
            clubsGrid.Width = width;
            clubsGrid.LayoutUpdated -= new EventHandler(clubsGrid_LayoutUpdated);
        }

Does this solve the problem?

Kind regards,
Didie
the Telerik team

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

0
swarmttied
Top achievements
Rank 1
answered on 25 Jan 2012, 08:00 PM
Works like a charm. Thanks.
Tags
GridView
Asked by
swarmttied
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
swarmttied
Top achievements
Rank 1
Share this question
or