Question

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

Was it helpful?

Solution

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

OTHER TIPS

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

GridView.BestFitColumns();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top