Numeric Data binded fields in maskedtextbox  
Author Message
Vinodonly





PostPosted: Windows Forms General, Numeric Data binded fields in maskedtextbox Top

A Data field having data type as numeric(6,3) is binded with Masked textbox with following mask property :-

00.000

Following code is given in form load :-

Me.MyMaskedTextBox.DataBindings("Text").FormatString = "00.000"

a value of 12.889 is displayed correctly as 12.889 whereas a value of 4.55 is displayed as 04.550, i want to remove both zero's from the display for this type of value.

can anybody help...



Windows Forms23  
 
 
Brendan Grant





PostPosted: Windows Forms General, Numeric Data binded fields in maskedtextbox Top

When specifying a formatting string for a number like that 0’s effectively mean ‘put a digit here even if there isn’t really one’ which is exactly what you are seeing. One of the easiest ways around this is to replace the 0’s in your format string to # signs which effectively mean ‘put something here only if there is something to put here’.

So in your example with that format string even a value of say... 1 would be displayed as: 01.000 while if you changed your format string to ‘##.0##’ (as an example) the output would be ‘1.0’.

Does this work for you



 
 
Vinodonly





PostPosted: Windows Forms General, Numeric Data binded fields in maskedtextbox Top

thanks for your reply.

but this is not working, for value of 2.554, it is showing 25.54_ !!! actually i have tried lot of combinations but none is working.

pls advs...


 
 
Brendan Grant





PostPosted: Windows Forms General, Numeric Data binded fields in maskedtextbox Top

So now you’ve got the string being displayed right without any extra characters but it is the MaskedTextBox that is getting in your way... unfortunately the point of the MaskedTextBox is to display in a graphic way what sort of input it will accept and it is kind of all or nothing.

Three things you could try to make your life easier here would be to modify the Mask property to include a few #’s in place of 0’s to make certain positions optional for validation purposes. Also, to eliminate the underlined missing character you can do two things... either set the HidePromptOnLeave property to true so that the missing digit(s) are not noticeable when you are not focused on the control, or set the PromptChar property to a space character so that it does not give the obvious underline prompts but still does the soft enforcement of character by character validation.



 
 
Vinodonly





PostPosted: Windows Forms General, Numeric Data binded fields in maskedtextbox Top

Kindly note that i already tried both options that is with mask property set with ## or mask property set with 00's, result is same i.e.

2.554 is being displayed as 25.54

thanks for second suggestion, now _ is gone


 
 
Vinodonly





PostPosted: Windows Forms General, Numeric Data binded fields in maskedtextbox Top

this is still not solved.

can you pls help in this, i already tried both options that is with mask property set with ## or mask property set with 00's, result is same i.e.

2.554 is being displayed as 25.54