문제

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

도움이 되었습니까?

해결책

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

다른 팁

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

GridView.BestFitColumns();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top