I have a windows forms app with a textbox control that I want to only accept integer values. In the past I\'ve done this kind of validation by overloading the KeyPress event
In button click you can check text of textbox by for loop:
char[] c = txtGetCustomerId.Text.ToCharArray(); bool IsDigi = true; for (int i = 0; i < c.Length; i++) { if (c[i] < '0' || c[i] > '9') { IsDigi = false; } } if (IsDigi) { // do something }