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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Maximum column widths for GridDataBoundGrid

Thread ID:





97114 Oct 28,2010 07:40 PM UTC Nov 1,2010 12:40 PM UTC WinForms 1
Tags: GridControl
Roland Brooks
Asked On October 28, 2010 07:40 PM UTC

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?


Nirmal Raja [Syncfusion]
Replied On 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
if (width < newWidth)
width = newWidth;
this.gridControl1.ColWidths[col] = width;

Let me know if you face any issues.



This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon