Display when numeric value exceed Cell width

Hi,

I am wondering if there exists a property or a way to display numberic cell value as ##### when the value exceeds cell width (just like the behavior in excel).

Currently, it only shows part of the value which could potentially lead to wrong reading.

BTW, I am using GridControl 5.2

Thanks,

Q


3 Replies

HA haneefm Syncfusion Team December 7, 2007 04:13 PM UTC

Hi Q,

You can do this dynamically in DrawCellDisplayText event. This way you do not modify the actual datatable values, but instead just change what the grid displays. In that event you need to set the e.DisplayText to some new value to want to display. Use the e.RowIndex and e.ColIndex to get the row and column of the cell for which the displaytext has to be set. Below is a code snippet.

private void DrawCellDisplayText(object sender, GridDrawCellDisplayTextEventArgs e)
{
if (e.RowIndex > 0 && e.ColIndex > 0)
{
SizeF siz = e.Graphics.MeasureString(e.Style.CellValue.ToString(), e.Style.GdipFont);
if ((siz.Width + 2) > e.ClipBounds.Width)
{
e.DisplayText = "##############";
}
}
}

Best Regards,
Haneef



QS Qingde Shi December 7, 2007 09:50 PM UTC

Hi Haneef,

Thanks. That works quite well.

one more related question, while setting the DispalyText as #####, how to set CellTipText to show what should have shown the FormattedText.

Do I have to set the CellTipText in QueryCellInfo when in vitual mode?

Thanks,

Q


>Hi Q,

You can do this dynamically in DrawCellDisplayText event. This way you do not modify the actual datatable values, but instead just change what the grid displays. In that event you need to set the e.DisplayText to some new value to want to display. Use the e.RowIndex and e.ColIndex to get the row and column of the cell for which the displaytext has to be set. Below is a code snippet.

private void DrawCellDisplayText(object sender, GridDrawCellDisplayTextEventArgs e)
{
if (e.RowIndex > 0 && e.ColIndex > 0)
{
SizeF siz = e.Graphics.MeasureString(e.Style.CellValue.ToString(), e.Style.GdipFont);
if ((siz.Width + 2) > e.ClipBounds.Width)
{
e.DisplayText = "##############";
}
}
}

Best Regards,
Haneef





HA haneefm Syncfusion Team December 7, 2007 11:24 PM UTC

Hi,

You can set the Style.CellTipText for the grid cell to show the tooltip in a grid. You can do this in QueryCellInfo.

private void grid_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
if(e.RowIndex > 0 && e.ColIndex == 3)
{
e.Style.CellTipText = e.Style.FormattedText;
//maybe .Text or some other string...
}
}

Best regards,
Haneef


Loader.
Up arrow icon