views:

108

answers:

1

Hi,

I'd like to make a textbox that accepts only numbers, but not integer, but rather double.
I've read here about e.Handled = Not Char.IsDigit(e.KeyChar) and it works, but again, it can be used only for integer, since it declines decimal point.
Another thing I've read here is If Not Double.TryParse(TextBox2.Text, value) Then .... and it would work fine, except that it allows only decimal comma instead of point. I don't know whether it's because of my location settings (Hungary, we use commas instead of points), but I don't have any other idea how to solve my problem, and the SQL server I send my data uses decimal point.

Thanks in advance.

+2  A: 

Pass CultureInfo.InvariantCulture to TryParse.

SLaks
Thanks, but I can't really make it, it seems. I tried to follow the guide VB gives and I came up with something like this: "If Not Double.TryParse(TextBox2.Text, style:=NumberStyles.AllowDecimalPoint, provider:=CultureInfo.InvariantCulture, result:=value)", but it still converts my decimal point to comma. :( Am I doing something wrong?
fema
If you call `ToString`, you need to pass `CultureInfo.InvariantCulture` there, too. Where is it getting converted to a comma?
SLaks
OMG! You are awesome! Thanks, it works perfectly!Btw, passing the CultureInfo.InvariantCulture also to ToString was the solution. :)
fema