How ToAccess dynamically added Rich Text Box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • varunbhatia87
    New Member
    • Apr 2009
    • 3

    #1

    How ToAccess dynamically added Rich Text Box

    I m creating a multi tab application. i m adding tab & RichTextBox in tab control through programming. i want to access the text of rich text box.
    plz help me....
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    myRichTextBox.T ext

    Very straight forward and direct

    Comment

    • pratham2003
      New Member
      • Apr 2009
      • 4

      #3
      @tlhintoq
      I had tried your suggestion before... but when you add control at run-time you cant directly refer to it using its name... The application wont compile...

      I havent used tabs in my applications yet..
      But you can find a richtextbox in your form by using the following method...

      Code:
      Dim form As ControlCollection = Me.Controls
      Dim richTxt as array
      richTxt = grpBox.Controls.Find("Richtxt", True)     
      ' Richtxt is the name property of the richtextbox you are searching for.
      
      'you can refer to its text property using...
      richTxt(0).text= "modify me .... .... ..."

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        You shouldn't have to go find it since you made it. You just need to add a little more to the part where you make it so you don't loose track of it.

        It would be much cleaner and easier if when you make the control you add it to known variable. Then you don't have to go looking for it later.

        Sorry the example is in C# instead of VB, but you should be able to follow.
        1. Make a member variable visible to all methods
        2. Add to it, the dynamically created textbox
        3. Later when you need it, you already know where it is

        Code:
        TextBox myNewTextbox;
        
        private void SetupControls()
        {
           myNewTextBox = new TextBox();
           myNewTextBox.Text = "Feed me Simore";
           myNewTextBox.Click += new MyNewTextBox_Click(ClickHandler);
        }

        Comment

        Working...