If the format of a data bound grid control is set to display negative values (in Static cells) as "#,0;(#,0)", and horizontal alignment is Right, it seems that negative values do not exactly line up with positive values in the same column. That is, the least significant digit of each value is not aligned within a column. It looks like the ")" interferes with correct alignment. Excel seems to handle this properly (or at least what I consider properly).
Is there a way to make the data bound grid behave like Excel in this regard?
Actually, I just noticed that even if the format string is set to "#,0;-#,0", it still fails to align the + and - values in a column, but the offset is much smaller than with "()" for - values.
ADAdministrator Syncfusion Team September 16, 2003 05:19 PM
The minus problem is in .NET. If you line up several labels vertically, align them right, and put + and - values in them, the text does not line up in the labels either. I think this has been fixed in .NET 1.1.
The paren problem is something else though. I think you can work around it with code like in a DrawCell event handler:
Clay, thanks for the response. Unfortunately, your suggestion does not work. I also tried
const string testValue = "100,000.00";
int sizePos = (int) e.Graphics.MeasureString(testValue, e.Style.GdipFont).Width;
int sizeNeg = (int) e.Graphics.MeasureString("(" + testValue + ")", e.Style.GdipFont).Width;
sizeParen = (sizeNeg - sizePos) / 2;
and that gets it closer but it's still off (by maybe 1 pixel). I'm not sure what XL uses to get it right no matter what the font, value, etc.
FWIW, I use v1.1 of the framework and the problem with the "-" sign is still there. I tried your idea of vertically aligned labels and the text does not align properly.