how to make backspace working?

Asked By Priyanka
06-Sep-10 01:01 AM
Earn up to 0 extra points for answering this tough question.

if (char.IsNumber(e.KeyChar) == false)

e.Handled = true;


i tried the above code on key press event for text box but backspace key is not working in it ... how to make it working?

  re: how to make backspace working?

harsh shah replied to Priyanka
06-Sep-10 01:13 AM
Hi,
try the below code


if (e.KeyChar == '\b')
   {
     e.Handled = false;
   }


let me know

Regards,

Harsh Shah

  re: how to make backspace working?

Priyanka replied to harsh shah
06-Sep-10 01:56 AM
 it is not working ...
 it also accepts  both type of values numeric and char.....

i want that text box donot accept char values but backspace should work in that text box...

  re: how to make backspace working?

harsh shah replied to Priyanka
06-Sep-10 02:05 AM
ok
given code is only for back space.
any way try below code it's accept only numeric and backspace.


if (e.KeyChar == '0' || e.KeyChar == '1' || e.KeyChar == '2' || e.KeyChar == '3' || e.KeyChar == '4' || e.KeyChar == '5' || e.KeyChar == '6' || e.KeyChar == '7' || e.KeyChar == '8' || e.KeyChar == '9' || e.KeyChar == '\b')
    {
     e.Handled = false;
    }
    else
   {
        e.Handled = True;
   }

Regards,

Harsh Shah
  re: how to make backspace working?
George replied to harsh shah
06-Sep-10 02:11 AM
Thanks from bottom of my heart.....
  re: how to make backspace working?
Priyanka replied to harsh shah
06-Sep-10 02:17 AM
Thank you so very much....
  re: how to make backspace working?
Anand Malli replied to Priyanka
06-Sep-10 02:21 AM
Hi Priyanka

I have created one small function for you,its completely different approch,there more then one way with which you can achieve this,i have developed one function which is as follows,just let me know,it is something which you want,just create KeyPress event of your textbox like following

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
   int[] numArr = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
   char bckSpace = '\b';
   int isInt = 0;
   bool blnIsInt = int.TryParse(e.KeyChar.ToString(), out isInt);
   e.Handled = (isInt != 0 || e.KeyChar == '\b') ? false : true;
          
}

i think code is self explanatory,if you have any doubt just let me know

THANKS 
  re: how to make backspace working?
Priyanka replied to Anand Malli
06-Sep-10 02:29 AM
Thanks you so very much ... it is working properly......
  re: how to make backspace working?
Anand Malli replied to Priyanka
06-Sep-10 02:44 AM
:)...its always good idea to discover new hacks...isnt it...gr8...
  re: how to make backspace working?
bhagavan replied to Priyanka
22-Jul-11 02:22 AM
 if ((e.KeyChar < '0') || (e.KeyChar > '9'))
        {
          if (e.KeyChar != '\b')
          {
            e.Handled = true;
          }
         
        }




It will work
Create New Account