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

BestFit() performance

6 Answers 382 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Alex Peachey
Top achievements
Rank 1
Alex Peachey asked on 07 Jan 2008, 07:31 PM
I didn't want to hijack this other thread, but as it talks about performance it is related:
http://www.telerik.com/community/forums/thread/b311D-bbbmem.aspx

In that thread you state that you are reworking the gridview for better performance and we should see something in the next release (2008 Q1?).

For the most part the gridview performance isn't that bad in my project, but one area it is extremely poor is using the BestFit() method on a column. I like to present a stylish output to the user and with dynamic data drawn from the database it is pure guessing to set the columns to a defined width. So after assigning a datasource, I loop over the columns and call BestFit(). This is very slow. I've taken to only doing it to a few key columns, but it would be nice to have the whole grid formatted nicely.

I just wanted to make sure improving performance of this method was part of the plan for the reworking of this control.

Thanks,

Alex

6 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 08 Jan 2008, 12:26 PM
Hi Alex Peachey,

Thank you for writing us.

We will improve the performance of  the BestFit method in our next release. Instead of iterating through all columns, you can use the BestFitColumns method of the MasterGridViewTemplate.

Refer to the following code snippet:

this.radGridView1.MasterGridViewTemplate.BestFitColumns(); 

We suggest calling the BeginUpdate and EndUpdate methods when changing more than one property that affects the visual elements in RadGridView.

The sample below demonstrates this approach:

this.radGridView1.GridElement.BeginUpdate(); 
foreach (GridViewColumn column in this.radGridView1.Columns) 
    column.BestFit(); 
this.radGridView1.GridElement.EndUpdate(); 
 

I hope this information helps you. If you have further questions, feel free to contact us.

Greetings,
Jack
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Atle
Top achievements
Rank 1
answered on 09 Jan 2008, 09:03 AM

Hi,

I tried both
this.radGridView1.MasterGridViewTemplate.BestFitColumns();
and
foreach (GridViewDataColumn col in radGridView1.Columns)
{
    col.BestFit();
}

Most columns ended up fitting it's content, but not all.
Even when I doubleClick between the columns in the grid they do not resize to fit the content correctly.

I'm running the application on Vista.

 

 

0
Jack
Telerik team
answered on 09 Jan 2008, 12:34 PM
Hi Atle,

When the AutoSizeColumnsMode property of the MasterGridViewTemplate is set to Fill, the column widths are adjusted so that the widths of all columns exactly fill the display area of the control.

Because of this not all columns can be best fit in Fill mode. If you want all columns to have exactly the specified width, set the AutoSizeColumnsMode to None.

Tell us if this information solves your problem.

Don't hesitate to contact us if you have other questions.

Kind regards,
Jack
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Atle
Top achievements
Rank 1
answered on 09 Jan 2008, 01:20 PM
The AutoSizeColumnsMode was set to None, so that did not solve the problem.

You wrote:
"...If you want all columns to have exactly the specified width, set the AutoSizeColumnsMode to None... "
Does this mean I have to specify the column width myself?

The weird thing is that even when doubleclicking between columns they resize to small. "Best fit" cuts a few letters.
0
Jack
Telerik team
answered on 09 Jan 2008, 02:09 PM
Hi Atle,

You don't need to specify the exact width of every column. You just need to call the BestFitColumns when the RadGridView is bounded. Maybe you are experiencing an issue with the calculation of the width of the columns.

Please send us a sample application which reproduces the behavior you described. It will help us address any potential issue faster.

If you have any additional questions, please contact us.

Greetings,
Jack
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Alex Peachey
Top achievements
Rank 1
answered on 09 Jan 2008, 03:30 PM
I just had a chance to try out this suggestion this morning and thank you! This is a much better way to handle this.
I changed the code from:
            SearchResultsGridView.DataSource = _results;
            foreach (GridViewColumn gvc in SearchResultsGridView.Columns)
            {
                gvc.BestFit();
            }
to:
            SearchResultsGridView.DataSource = _results;
            SearchResultsGridView.GridElement.BeginUpdate();
            SearchResultsGridView.MasterGridViewTemplate.BestFitColumns();
            SearchResultsGridView.GridElement.EndUpdate();

The results come up formatted much quicker. I'd say there is still some room for speed improvement but it went from painfully unusable to quite usable with this change.
Tags
GridView
Asked by
Alex Peachey
Top achievements
Rank 1
Answers by
Jack
Telerik team
Atle
Top achievements
Rank 1
Alex Peachey
Top achievements
Rank 1
Share this question
or