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.
Unfortunately, activation email could not send to your email. Please try again.

Maximum column widths for GridDataBoundGrid

Thread ID:

Created:

Updated:

Platform:

Replies:

97114 Oct 28,2010 03:40 PM Nov 1,2010 08:40 AM Windows Forms 1
loading
Tags: GridControl
Roland Brooks
Asked On October 28, 2010 03:40 PM

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

Nirmal Raja [Syncfusion]
Replied On November 1, 2010 08:40 AM

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



CONFIRMATION

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.

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.

;