Click here to Skip to main content
15,905,229 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can you help me with this error

Argument 1: cannot convert from 'decimal' to 'string'

C#
if (int.TryParse(numericUpDownLowerLimit.Value, out MINLENGTH) == false || int.TryParse(numericUpDownUpperLimit.Value, out MAXLENGTH) == false)
            {
                ShowErrorBox("Min and Max lengths must be valid integers.");
                return;
            }
Posted
Updated 5-Feb-14 4:54am
v3

The Value property of a NumericUpDown is not a string - it's a decimal value, so you don;t need to try and parse it.
Equally, it can be set to be always a valid integer by leaving the DecimalPlaces property at zero - all you need to do then is cast it to an int
 
Share this answer
 
Comments
Nico_Travassos 5-Feb-14 10:57am    
so basically just remove TryParse and keep int
OriginalGriff 5-Feb-14 11:00am    
Well, yes - but you don;t need the if test at all, because the user can't enter an invalid value! :laugh:
Thomas Daniels 5-Feb-14 11:02am    
+5!
Nico_Travassos 5-Feb-14 11:05am    
Thank you
OriginalGriff 5-Feb-14 11:06am    
You're welcome!
The value of a NumericUpDown is always a decimal, never a string. So you'll need to cast it to an int:
C#
int MINLENGTH = (int)numericUpDownLowerLimit.Value;
int MAXLENGTH = (int)numericUpDownUpperLimit.Value;
 
Share this answer
 
v2
Comments
OriginalGriff 5-Feb-14 11:01am    
*cough* decimal *cough*
Thomas Daniels 5-Feb-14 11:01am    
Fixed.
Nico_Travassos 5-Feb-14 11:05am    
Thank you
Thomas Daniels 5-Feb-14 11:05am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900