This is a migrated thread and some comments may be shown as answers.

RadDropDown Text Validation

3 Answers 157 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Sr
Top achievements
Rank 1
Sr asked on 03 Jul 2012, 08:01 PM
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.

3 Answers, 1 is accepted

Sort by
0
Accepted
Stefan
Telerik team
answered on 05 Jul 2012, 06:19 AM
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 >>
0
Sr
Top achievements
Rank 1
answered on 05 Jul 2012, 05:21 PM
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.
0
Stefan
Telerik team
answered on 09 Jul 2012, 11:58 AM
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 >>
Tags
DropDownList
Asked by
Sr
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Sr
Top achievements
Rank 1
Share this question
or