kashif
kashif

Reputation: 3834

how to Best Fit(All Columns) in a GridControl

How to best fit all the columns in a grid control when form is loaded. I do have a button as shown in the following picture to do that when i right click the header of the grid control, but as opposed to this I want this event to be fired automatically when the form is loaded. I don't want to do this by right clicking the header of the grid control and than clicking the Best Fit(all columns) button to best fit all the columns. enter image description here

Upvotes: 1

Views: 20229

Answers (2)

kashif
kashif

Reputation: 3834

following Code BestFit All the Columns Provided that FixedWidth of All the Columns is set to False

GridView.BestFitColumns();

Upvotes: 3

Stig
Stig

Reputation: 1323

This is how I do it.

if (view is GridView)
{
   // auto best fit...
   (view as GridView).BestFitMaxRowCount = 5000;   // just to avoid to many compares
   (view as GridView).BestFitColumns();
   foreach (GridColumn item in (view as GridView).Columns) // reduce the width of very wide columns
   {
      item.Width = (item.Width > 1000) ? 1000 : item.Width;
   }
}

Upvotes: 6

Related Questions