Only accepts numeric characters.

8 posts, 0 answers
  1. Chubi
    Chubi avatar
    5 posts
    Member since:
    Feb 2012

    Posted 17 Feb 2013 Link to this post

    I need to create one RadDropDownList control in which user can enter only digits but not characters.
    Hope I Will get answer soon, Thanks
  2. Plamen
    Admin
    Plamen avatar
    132 posts

    Posted 19 Feb 2013 Link to this post

    Hello Chubi,

    Thank you for writing.

    You can achieve such behavior by using the TextChanging event of the inner text box. Here is a sample code:
    this.radDropDownList1.DropDownListElement.EditableElement.TextBox.TextBoxItem.TextChanging += new Telerik.WinControls.TextChangingEventHandler(TextBoxItem_TextChanging);
     
    void TextBoxItem_TextChanging(object sender, Telerik.WinControls.TextChangingEventArgs e)
    {
        e.Cancel = e.NewValue.Any(character => !char.IsNumber(character));
    }

    Attached you can find a sample project, which demonstrates this functionality.

    I hope this helps.

    All the best,
    Plamen
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Chubi
    Chubi avatar
    5 posts
    Member since:
    Feb 2012

    Posted 20 Feb 2013 Link to this post

    Mr. Plamen
    Thank you for You reply.
    And here I would like to get VB.net(2010) Code but not C# or other
    Thanking you again for your valuable reply..
  5. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 20 Feb 2013 Link to this post

    Hi Chubi,

    Here is the VB version of the code snippet:
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
           AddHandler RadTextBox1.TextBoxElement.TextBoxItem.TextChanging, AddressOf TextBoxItem_TextChanging
       End Sub
     
       Private Sub TextBoxItem_TextChanging(sender As Object, e As Telerik.WinControls.TextChangingEventArgs)
           e.Cancel = e.NewValue.Any(Function(character) Not Char.IsNumber(character))
       End Sub

    In future, if you need such to convert code from C# to VB and vice versa, you can try our free online converter at: http://converter.telerik.com/.

    I hope this helps.
     

    Kind regards,
    Stefan
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
  6. Chubi
    Chubi avatar
    5 posts
    Member since:
    Feb 2012

    Posted 20 Feb 2013 Link to this post

    Mr.Stefan
    Thank you for You reply.
    I Used your free tool 'telerik converter' to convert first code which you have given, but I am getting Error (It is not converted).
    And about your reply, I need Codes for "RadDropDownList" not for "RadTextBox1" 

    I have made one modification in your code as given below...

    "AddHandler RadTextBox1.TextBoxElement.TextBoxItem.TextChanging, AddressOf TextBoxItem_TextChanging"

    Changed To..

    "AddHandler RadDropDownList1
    .DropDownListElement.EditableElement.TextBox.TextBoxItem.TextChanging, AddressOf TextBoxItem_TextChanging"

    its ok..
    but getting error near code  "e.NewValue.Any"       (e.Cancel = e.NewValue.Any(Function(character) Not Char.IsNumber(character)))
    VB Says " 'Any' is not a member of string. "

    Pleas give your valuable reply.
  7. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 22 Feb 2013 Link to this post

    Hi Chubi,

    Please excuse me for the confusion. The error you are getting is because you are using a .NET version prior .NET3.5. Here is the code for versions where lambdas are not supported:
    Private Sub TextBoxItem_TextChanging(sender As Object, e As Telerik.WinControls.TextChangingEventArgs)
            'e.Cancel = e.NewValue.Any(Function(character) Not Char.IsNumber(character))
            e.Cancel = Not IsNumeric(e.NewValue)
        End Sub

    I hope this helps.

    All the best,
    Stefan
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
  8. Chubi
    Chubi avatar
    5 posts
    Member since:
    Feb 2012

    Posted 22 Feb 2013 Link to this post

    Hello Stefan,

     I did as u said, but I can't enter the number except in the format given in code snippet ("0123456789"), I mean I Can enter only in ascending order not any other numbers(example: 1324, 156, 10). And I am using .net framework version 4
    Hope I will get the Solution
  9. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 27 Feb 2013 Link to this post

    Hi Chubi,

    Please excuse me for the misunderstanding. I have updated the code snippet in my previous post and it should be working correctly now.

    As to the lambdas, I am not sure why it does not work in your case. The error you have provided is raised when the framework version is less than 3.5. With 3.5 and 4.0 I am able to use it. See attached video (opens in browser).

    All the best,
    Stefan
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
Back to Top
UI for WinForms is Visual Studio 2017 Ready