RadDropDown Text Validation

4 posts, 1 answers
  1. Sr
    Sr avatar
    5 posts
    Member since:
    Jul 2012

    Posted 03 Jul 2012 Link to this post

    Hi,

    I have a RadDropdownlist which should allow the user to type in only numeric values in it. Validations in Key_Down and Key_Press event does fire but it is not working. I have similar validations for normal textboxes and it is working.

    Is there are any ways to restrict the user to type only numeric values in RadDropDown?

    private bool nonNumberEntered = false;
     protected void radDDLAccountNo_KeyDown(Object sender, KeyEventArgs e)
            {
                ValidateNumericField(e);
            }
            private void radDDLAccountNo_KeyPress(Object sender, KeyPressEventArgs e)
            {
                KeyPressEvent(e);           
            }
    private void ValidateNumericField(KeyEventArgs e)
            {
                nonNumberEntered = false;
                if (e.KeyCode < Keys.D0 || e.KeyCode > Keys.D9)
                {
                    if (e.KeyCode < Keys.NumPad0 || e.KeyCode > Keys.NumPad9)
                    {
                        if (e.KeyCode != Keys.Back)
                            nonNumberEntered = true;
                    }
                }
                if (Control.ModifierKeys == Keys.Shift)
                    nonNumberEntered = true;
            }
            private void KeyPressEvent(KeyPressEventArgs e)
            {
                if (nonNumberEntered == true)
                {
                    e.Handled = true;
                }
            }
       

    Thank you in advance for the help.

  2. Answer
    Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 05 Jul 2012 Link to this post

    Hello,

    Thank you for writing.

    I have tested your code with our latest version is it seems to be working OK. Attached you can find a sample project demonstrating my tests. Additionally, you can find another way to achieve the same - by using the TextChanging event of the inner text box. 

    If you continue experiencing such issues, please open a new support ticket and attach your project there. We will investigate the reasons causing them and we will get back to you.
     
    Kind regards,
    Stefan
    the Telerik team
    RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Sr
    Sr avatar
    5 posts
    Member since:
    Jul 2012

    Posted 05 Jul 2012 Link to this post

    Thank you Stefan.

    DropDownListElement.EditableElement.TextBox.TextBoxItem.TextChanging worked well. When I was browsing through the forums/tutorials, I could not find there is such event exist. Is there any place where you guys list all the properties/events of controls?

    Thanks again for the help.
  5. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 09 Jul 2012 Link to this post

    Hello,

    The members of a class can be found in our API reference documentation, which is part of our online documentation. Here is a link to the desired RadDropDownListElement members:http://www.telerik.com/help/winforms/allmembers_t_telerik_wincontrols_ui_raddropdownlistelement.html

    I hope this helps.

    Greetings,
    Stefan
    the Telerik team
    RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
Back to Top