StrataFrame Forum

Subclassed Devexpress TextEdit not displaying correctly

http://forum.strataframe.net/Topic30614.aspx

By Ger Cannoll - 11/17/2011

I have a Subclassed Devexpress TextEdit control, where I want a Numeric Field, displaying 2 decimal points. This does not show the decimal points mask, unless I Click into the control. If the value has zero init , it displays as 0  (Not 0.00). The minute I click into it , or Edit it, it displays correctly. I have tried the same thing with the Devex Control itself dropped on the form, and manually set the Properties (For which I have Code in the Subclass) , and it works fine.

Also, if I set the properties manually on the form in my subclassed control, it also shows the 2 decimals

My subclass code is as follows:

public class dxTextEdit2D : dxTextEdit
{
protected override void OnEnter(EventArgs e)
{
base.OnEnter(e);
this.Properties.Mask.UseMaskAsDisplayFormat = true;
this.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
this.Properties.EditFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
this.Properties.EditFormat.FormatString = "###,####,###,##0.00";
this.Properties.DisplayFormat.FormatString = "###,####,###,##0.00";
this.Properties.Mask.MaskType = DevExpress.XtraEditors.Mask.MaskType.Numeric;
this.Properties.Mask.EditMask = "n02";
}
} // End dxTextEditN2


I have also attached a screen shot of whats happening

 

By Edhy Rijo - 11/17/2011

Hi Ger,

Ger Cannoll (11/17/2011)
this.Properties.Mask.EditMask = "n02";


I believe that the EditMask should be "n2" Also, use the New() constructor instead of the OnEnter.
By Trent L. Taylor - 11/18/2011

That would be my first reaction as well.  Masking is fairly consistent in .NET.  There are a number of help topics in the standard .NET help about masking and formatting.  3rd party controls generally stick to these standards for the most part.  If you look through this article, string.Format, you will find a lot of link that take you to data type specific formats that will give you a ton of information on the standard formats.  These formats, like Edhy mentions (n2) will ring true. 

There are other options too for optional values, like "0,0.0##". In this format, comma separators will be used and at least 1 decimal place will be forced.  But up to 3 decimal placed will be allowed.  So I would recommend researching some of this as there is a treasure trove of information if you dig deep enough.
By Ger Cannoll - 11/19/2011

Trent, Edhy, thanks for replying.

I think the n02 is ok as it was working when I set focus on the control. I got a reply back from Devexpress who pointed me in the right direction , similar to Edhy's suggestion  as to where to put the Event code, so am now also over-riding the InitializeDefaultProperties event, and its working fine now.

The Control.Enter event occurs when the control becomes focused. If you wish to use the mask by default, I suggest you override the InitializeDefaultProperties method:
protected override void InitializeDefaultProperties()
            {
                base.InitializeDefaultProperties();
                this.Properties.Mask.UseMaskAsDisplayFormat = true;
                this.Properties.Mask.MaskType = DevExpress.XtraEditors.Mask.MaskType.Numeric;
                this.Properties.Mask.EditMask = "n02";
            }