BestFit() performance

7 posts, 0 answers
  1. Alex Peachey
    Alex Peachey avatar
    56 posts
    Member since:
    May 2006

    Posted 07 Jan 2008 Link to this post

    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
  2. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 08 Jan 2008 Link to this post

    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
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Atle
    Atle avatar
    13 posts
    Member since:
    Dec 2007

    Posted 09 Jan 2008 Link to this post

    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.

     

     

  5. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 09 Jan 2008 Link to this post

    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
  6. Atle
    Atle avatar
    13 posts
    Member since:
    Dec 2007

    Posted 09 Jan 2008 Link to this post

    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.
  7. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 09 Jan 2008 Link to this post

    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
  8. Alex Peachey
    Alex Peachey avatar
    56 posts
    Member since:
    May 2006

    Posted 09 Jan 2008 Link to this post

    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.
Back to Top
UI for WinForms is Visual Studio 2017 Ready