Jelmer Posted March 6, 2006 Posted March 6, 2006 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? Quote
Cags Posted March 6, 2006 Posted March 6, 2006 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. Quote Anybody looking for a graduate programmer (Midlands, England)?
Leaders snarfblam Posted March 6, 2006 Leaders Posted March 6, 2006 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. Quote [sIGPIC]e[/sIGPIC]
Cags Posted March 7, 2006 Posted March 7, 2006 My bad, I didn't realise that as I'm used to using int's. Quote Anybody looking for a graduate programmer (Midlands, England)?
Jelmer Posted March 7, 2006 Author Posted March 7, 2006 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 = ""; } } Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.