Avatar of Petermcg001
Petermcg001
Flag for United Kingdom of Great Britain and Northern Ireland asked on

Populate text box on tab page in tab control

Hello,

I have a data entry form with a tab control with a number of pages.  On load my form populates a number of the text boxes.  The problem is populating text boxes which are on the non-active tab page. Only the text boxes on the front page can be populated.  For instance "EmailAddressTextBox.Text = .Item("EmailAddress")" only works if the EmailAddressTextBox.Text is on the first tab on on the main form itself.

Thank.
Visual Basic.NETMicrosoft Development.NET Programming

Avatar of undefined
Last Comment
Petermcg001

8/22/2022 - Mon
John (Yiannis) Toutountzoglou

hi
The Controls in tabcontrol are created when the tabpage has focus...
use selecetedindex event to populate the EmailAddres TextBox...

John...
Mike Tomlinson

It works fine for me...VS2010 running on Win8.

All ten TextBoxes, one in each Tab, got populated from the Load() event:
Public Class Form1

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        TextBox1.Text = "1"
        TextBox2.Text = "2"
        TextBox3.Text = "3"
        TextBox4.Text = "4"
        TextBox5.Text = "5"
        TextBox6.Text = "6"
        TextBox7.Text = "7"
        TextBox8.Text = "8"
        TextBox9.Text = "9"
        TextBox10.Text = "10"
    End Sub

End Class

Open in new window

ASKER CERTIFIED SOLUTION
John (Yiannis) Toutountzoglou

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
John (Yiannis) Toutountzoglou

In the above case if the CheckBox Is not DataBound the CheckState changes also in Form Load Event As Idle Mind said..
If it is...then it does not...


I think  that this is because the Binding is initialized when a control is shown
Yiannis
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
John (Yiannis) Toutountzoglou

Petermcg001

ASKER
Hello, thanks for looking at this.

Yes, it's correct that non-bound controls work on the load event but data bound controls do not.  Populating the controls using the selectedindexchanged event approach works fine.  You just have to put a check mechanism in place to prevent the textboxes being re-populated each time the user selects the tab page and changing any modifications they have made - I've taken a simplistic approach so I've added the following to the event:-


If TabControl1.SelectedIndex = 1 Then
If inttabpage1 = 1 then
' user has already selected tabpage so don't trigger repopulate.
else
'populate text boxes
inttabpage1 = 1

end if


thanks again