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
close icon

Maximum column widths for GridDataBoundGrid

I'm using version 8.303.0.21 of the GridDataBoundGrid for Windows Forms. Using Visual Studio 2008.

I have a large text string in a cell of a column. I used ResizeToFit as described in the examples, but the column seems to stop at 75 characters wide instead of the 108 that are in the text string. The header title is set to be centered, but the actual location is almost to the right of the cell.

When I set the column width in code (to say 5000) that same effect happens. From looking at the grid it appears when I scroll over the cell is only the width of the entire grid.
(See the attached image)

Is there a way to make the width the same size as the text string, even if this means having to scroll to the right twice to view the entire string?



ColumnWidthExample_99f02e50.zip

1 Reply

NR Nirmal Raja Syncfusion Team November 1, 2010 12:40 PM UTC

Hi Roland,

Thank you for your interest in Syncfusion products.

You can implement the following method which will manually calculates the text and provide width to the specific column cells.


int width;
private void ResizeColumnsToFit()
{
for (int col = 1; col <= this.gridControl1.ColCount; col++)
{
width = 0;
for (int row = 1; row <= this.gridControl1.RowCount; row++)
{
GridStyleInfo style = this.gridControl1[row, col];
Graphics g = this.gridControl1.CreateGraphics();
int newWidth = (int)g.MeasureString(style.Text, style.Font.GdipFont).Width + 15; //+15 is margins
g.Dispose();
if (width < newWidth)
width = newWidth;
}
this.gridControl1.ColWidths[col] = width;
}
}


Let me know if you face any issues.

Regards,
Nirmal



Loader.
Live Chat Icon For mobile
Up arrow icon