How to empty textbox.text after event?

2 posts, 0 answers
  1. ZHOU
    ZHOU avatar
    10 posts
    Member since:
    Feb 2014

    Posted 27 Aug 2014 Link to this post

    I was trying to empty those textbox text after the event
    Thats what i have now:
                               
     foreach (Control ctrl in this.Controls)
      {
             RadControl rc = ctrl as RadControl;
                                    
             if (rc is TextBox)
               {
                    rc.Text = "";
               }
     
      }

    Any help will be appreciated , thanks
  2. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 01 Sep 2014 Link to this post

    Hello Zhou,

    Thank you for writing.

    I am not sure what exactly is the specific case, but following your sample code I noticed that you are trying to cast a RadControl to MS TextBox instance, which is not supposed to succeed. In order to clear the text from all RadTextBox controls, you must cast to RadTextBox:
    private void radButton1_Click(object sender, EventArgs e)
    {
        foreach (Control ctrl in this.Controls)
        {
            RadControl rc = ctrl as RadControl;
                             
            if (rc is RadTextBox)
            {
                rc.Text = "";
            }
        }
    }

    I hope this information helps. Should you have further questions, I would be glad to help.

    Regards,
    Desislava
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top