Thursday, June 12, 2014

Allowing only 0-9 values + Back button only (C#, Windows mobile 6.5)

        Handling Numeric fields, Allowing only 0-9 values + Back button only. 

       //Sample Text box.

        private void textBoxLongStalk_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = (Utility.KeyPress(sender, e) == false) ? true : false;
        }


         //Common function to handle numeric only restriction
        public static Boolean KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((e.KeyChar >= (char)Keys.D0 && e.KeyChar <= (char)Keys.D9) || (e.KeyChar ==                                                                                                                                                       (char)Keys.Back))
            {
                return true;
            }
            else
            {
                return false;
            }
        }

No comments:

Post a Comment

Postgress - Read a XML file from a postgress table XML column

SELECT xmltable.* FROM xmldata, XMLTABLE('//ROWS/ROW' PASSING data COLUMNS id int PATH ...