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

Alignment of negative values

Thread ID:





7230 Sep 16,2003 07:53 PM UTC Sep 17,2003 06:32 PM UTC WinForms 3
Tags: GridControl
Peter Zaborski
Asked On September 16, 2003 07:53 PM UTC

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? -Peter

Peter Zaborski
Replied On September 16, 2003 08:00 PM UTC

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.

Administrator [Syncfusion]
Replied On September 16, 2003 09:19 PM UTC

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:
private void gridDataBoundGrid1_DrawCell(object sender, GridDrawCellEventArgs e)
	if(e.Style.CellValueType == typeof(double))
		string s = e.Style.CellValue.ToString();
		if(s.Length != 0)
			double d = double.Parse(s);
			if(d >= 0 )
				int sizeParen = (int)  e.Graphics.MeasureString(" ", e.Style.GdipFont).Width;
			e.Style.TextMargins.Right += sizeParen;

Peter Zaborski
Replied On September 17, 2003 06:32 PM UTC

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. -Peter


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

This page will automatically be redirected to the 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

Live Chat Icon For mobile
Live Chat Icon