 |
|
 |
I added NumericTextBox.cs to the my project (on Microsoft Visual Studio 2008 Express C#).
When I try to put NumericTextBox control from ToolBox, I have error:
Failed to create component 'NumericTextBox'. The error message follovs:
'System.FormatException: Input string was not in a correct format.
at System.ComponentModel.ReflectorPropertyDescriptor.SetValue(Object component, Object value) ...
Help me, please
|
|
|
|
 |
|
 |
well, its a case of "crappy" coding
Convert.ToDecimal Method (String)
throws those exceptions
if Decimal.TryParse was used or the exceptions were catched correctly there was no problem
in
protected string FormatNumber() {
use this
Decimal temp;
if (decimal.TryParse(this.Text, out temp)) {
return temp.ToString(lsb_Format.ToString());
} else {
return "0";
}
at the end of the method and it works
|
|
|
|
 |
|
 |
Not working in Visual Studio 2010
So, replace ANY Convert.ToDecimal and Convert.ToDouble methods with ConvertToDecimal and ConvertToDouble.
private Decimal ConvertToDecimal(object value)
{
Decimal temp;
if (!decimal.TryParse(this.Text, out temp))
{
temp = 0M;
}
return temp;
}
private Double ConvertToDouble(object value)
{
Double temp;
if (!double.TryParse(this.Text, out temp))
{
temp = 0D;
}
return temp;
}
|
|
|
|
 |
|
 |
Thanks for the great information, it was very helpful.Thanx,Prefabrik Ev
|
|
|
|
 |
|
 |
Hi, I am new to c# and was very excited to find this control. It does what I just need except that it doesn't allow user to leave the control unless I input a number other than 0. I can't tab away or mouse click another control.
Thanks,
|
|
|
|
 |
|
 |
Dear Sir,
This seems like a great control. It would be nice if it also handled decimals.
Okay, here's my bug. I have a little something in the clipboard that is invalid for the textbox:
Numeric TextBox : Allow your users to enter numeric data the easy way[^]
I noticed that your component doesn't allow the good-ol CTRL+V, however, it certainly does not block right-click, Paste. When I did that, there was an error (on the Convert.ToDecimal line). Otherwise, seems like a good go!
In Christ,
Aaron Laws
http://ProCure.com
|
|
|
|
 |
|
 |
failed to create component ,input string was not in correct format
saritha
|
|
|
|
 |
|
 |
private void testbox1_KeyPress(object sender, KeyPressEventArgs e)
{
const char Delete = (char)8;
e.Handled = !Char.IsDigit(e.KeyChar) && e.KeyChar != Delete;
}
|
|
|
|
 |
|
 |
I can't seem to find this anywhere in the code so when I try to add the control to my form it aborts "...Input string was not in the correct format".
Help!
Changed the following lines in NumericTextBox_TextChanged:
idec_InternalValue = Convert.ToDecimal(this.Text);
this.NumericValue = Convert.ToDecimal(this.Text);
to:
try
{
idec_InternalValue = Convert.ToDecimal(this.Text);
this.NumericValue = Convert.ToDecimal(this.Text);
}
catch (FormatException)
{
this.Text = "0";
}
|
|
|
|
 |
|
 |
Never mind...I had the code in the wrong place.
|
|
|
|
 |
|
 |
It seems there is no way to set the Text Alignment to Left in the control. It keeps moving back to Right and the code doesn't get serialized to the Designer code. Any way to fix this?
|
|
|
|
 |
|
 |
Comment out the line:
this.TextAlign = HorizontalAlignment.Right;
rg
|
|
|
|
 |
|
 |
Thanks for sharing. I find it very helpful.
|
|
|
|
 |
|
 |
Very good control. It has everything i wanted from NumericTextBox except pasting from clipboard.
It was very helpful, thanx.
|
|
|
|
 |
|
 |
how do i place (visually) the control to a Windows form ???
|
|
|
|
 |
|
 |
answered my own question... Controls.Add(numericTextBox1);
|
|
|
|
 |
|
 |
Can you modify it to add Range, Min and Max values it allows ?
Thanks
Vivek
|
|
|
|
 |
|
 |
Hi,
I was wondering if there is a way to load your control onto the "Toolbox->Common controls"? It would be handy to be able to drop it onto a form like a regular textbox.
And great control !!!
Neil Squires
|
|
|
|
 |
|
 |
As far as I know this is possible (VS2K5 and VS2K8) only if you add the control project to your solution and then build the whole.
If you just add the control's reference to the solution then you have to add the control in your code...
If anyone knows a better technique let'us know !
|
|
|
|
 |
|
 |
Right click on ToolBox an click 'Choose Items...'. On the '.NET Framework Components' tab, click the 'Browse...' button and select your assembly. Then you can select the controls you want to add to toolbox from the assembly. Click Ok and you're done.
|
|
|
|
 |
|
 |
Thanx for the control ! Indeed u have done a really good job !
But still I got a problem I cannot handle with ! An exception is thrown when I try to add it on the form at design time !
It says:
"System.FormatException was unhandled
Message="Input string was not in a correct format."
Source="mscorlib"
StackTrace:
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseDecimal(String value, NumberStyles options, NumberFormatInfo numfmt)
at System.Decimal.Parse(String s, IFormatProvider provider)
at System.Convert.ToDecimal(String value)
at Shorty.Windows.Forms.NumericTextBox.NumericTextBox_TextChanged(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnTextChanged(EventArgs e)
at System.Windows.Forms.TextBoxBase.OnTextChanged(EventArgs e)
at System.Windows.Forms.Control.set_Text(String value)
at System.Windows.Forms.TextBoxBase.set_Text(String value)
at System.Windows.Forms.TextBox.set_Text(String value)
at WinAppNumericTextBox.Form1.InitializeComponent()
at WinAppNumericTextBox.Form1..ctor()
at WinAppNumericTextBox.Form1.Main()"
Is there any way to get around with it ?
( Product Info:
Microsoft Visual Studio 2005
Version 8.0.50727.42 (RTM.050727-4200)
Microsoft .NET Framework
Version 2.0.50727
)
And one more thing that may help to fix the problem. When I Create control in a program way on my own it goes fine !
|
|
|
|
 |
|
 |
I got the same problem
Never underestimate capability and overestimate experience
|
|
|
|
 |
|
 |
This is because the designer is setting the Text property of the control to the normal text box default (e.g. textBox1) which then throws when trying to convert to decimal in NumericTextBox_TextChanged
The Text property shouldn't really be shown in designer (or should be given a sensible default), however a quick attempt at doing this didn't work, so for the moment I've changed the following lines in NumericTextBox_TextChanged:
idec_InternalValue = Convert.ToDecimal(this.Text);
this.NumericValue = Convert.ToDecimal(this.Text);
to:
try
{
idec_InternalValue = Convert.ToDecimal(this.Text);
this.NumericValue = Convert.ToDecimal(this.Text);
}
catch (FormatException)
{
this.Text = "0";
}
richard
|
|
|
|
 |
|
|
 |
|
 |
That's an awesome control.
But I noted that the control does not accept Ctl-C, Ctrl-V and Ctrl-X. Instead, right-click context menu (Cut, Copy and Paste) is regulary accepted.
Is there a fix for this?
Thank you.
c
|
|
|
|
 |