Note that there are some explanatory texts on larger screens.

plurals
  1. POOnly allow digits in textbox C#
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/2882369/how-can-i-allow-only-0-or-1-to-be-entered-in-a-textbox">How can I allow only 0 or 1 to be entered in a TextBox?</a><br> <a href="https://stackoverflow.com/questions/11656217/allow-only-integers-in-textboxes">Allow only integers in TextBoxes</a> </p> </blockquote> <p>I'm working on a program now and I have a few simple <code>textboxes</code>. I keep getting an error when the input of the <code>textbox</code> is NOT a number, because it tries to convert it to a integer.</p> <p>The code is very basic:</p> <pre><code> int optelNumber = Convert.ToInt32(textBox2.Text); MessageBox.Show("Please enter a digit."); //if optelNumber is not a digit </code></pre> <p>for example:</p> <pre><code>input in textbox = "Hello !" =&gt; pops up the Mess.Box input in textbox = 123245 =&gt; keep running the program </code></pre> <p>Hope this is enough information. I've searched almost all other topics but all the code was to advanced for me. :( Thanks for your time</p> <ul> <li>edit : </li> </ul> <p>The <code>messagebox</code> is to catch the error and keep the program from crashing.</p> <ul> <li><p>edit :</p> <pre><code>int vedett = 0, duvel = 0, kDuvel = 0, kriek = 0, pils = 0; //only digits allowed here int optelNumber = Convert.ToInt32(textBox2.Text); switch(comboItem) { case "vedett": vedett += optelNumber; break; case "duvel": duvel += optelNumber; break; case "kl. duvel": kDuvel += optelNumber; break; case "pils": pils += optelNumber; break; case "kriek": kriek += optelNumber; break; case "": MessageBox.Show("Kies een andere drank."); break; } </code></pre></li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload