Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I've got a textifield, i like to control if its a nummeric input if the user changes the text. It should be a rounded number or a double with 2 digits

 

how can i control if its a nummeric input?

Posted

You will have to check if the value they input is valid in either one of the Key events, or in one of the Validation events. If you are using the 2.0 framework this can be done using the double.TryParse() method. If you are using the 1.0/1.1 framework you will have to use double.Parse() and catch the exception.

Alternatively if you change one of the key events of the textbox you can allow only the number keys.

Anybody looking for a graduate programmer (Midlands, England)?
  • Leaders
Posted
The double data type also supports TryParse in .Net 1.x. The difference is that in 1.x, double is the only data type that supports TryParse, whereas in .Net 2.0, most native types support it.
[sIGPIC]e[/sIGPIC]
Posted

Thanx.. is works with this code:

 

private void txtPrijs_Validating(object sender, CancelEventArgs e)

{

double prijs;

if (Double.TryParse(txtPrijs.Text,out prijs)){

}else{

MessageBox.Show("Voer een correcte prijs in!");

txtPrijs.Text = "";

}

 

}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...