We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

GridControl Column autofit to the size of its cell value

I want to set the column of grid control to get autosized based on the cell value. The column is of type Combobox.

i have tried this but still no use

Model.ColWidths.ResizeToFit(this.GridCellsRange, GridResizeToFitOptions.IncludeHeaders);

1 Reply

AK Arun Kumar V Syncfusion Team July 12, 2013 08:41 AM UTC

Hi Pallavi,
Thanks for your interst in Syncfusion products.
To Reset the column width based on the cellvalue resizetofit method will work. Could you please let me know the exact essential studio version you are using.
You can also make use of the following method.
private void customizeWidth()
 Size stringSize;int temp = 0;
 for (int col = 0; col <= this.gridGroupingControl1.TableModel.ColCount; col++)
  for (int row = 0; row <= this.gridGroupingControl1.TableModel.RowCount; row++)
    stringSize = TextRenderer.MeasureText(this.gridGroupingControl1.TableModel[row,col].Text, Font);
             if (stringSize.Width > temp)
               temp = stringSize.Width;
             if (row == this.gridGroupingControl1.TableModel.RowCount)
                this.gridGroupingControl1.TableModel.ColWidths[col] = temp + 15;
                temp = 0;
please let me know if you have any concerns.

Live Chat Icon For mobile
Up arrow icon