none
Retrieving Data Values From TabPages RRS feed

  • Question

  • Hi:

    Call me Columbo, but I have one more question. My form has a tab control with just two tab pages.

    There are labels and textboxes on both tab pages that are bound to a datatable. On occasion I need

    to use  a value from one of the textboxes on tabpage #2 when tabpage #1 is active. The value is not

    accessible as tabpage #2 is not active. My question: Is there any way  to make the tabpage #2 values

    available without making tabpage #2 active, that is, loading it into a string or integer variable?

    Thanks


    Thursday, July 11, 2019 7:07 PM

All replies

  • Hi

    Not exactly clear on the issue you are asking about.

    Here is some code to illustrate the use of TextBoxes from non-active TabPages.

    There is a TextBox on TabPage1 with some text.

    There is a TextBox and a Button on TabPage2.

    There is a TextBox and a Button on TabPage3.

    There is a TextBox and a Button on TabPage4.

    when a Button ix clicked, it copies the text from TabPage1 TextBox1 to the TextBox on the TabPage where the Button was clicked. What part of that seems to cause an issue with you?

    Option Strict On
    Option Explicit On
    Public Class Form1
    	Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    		TextBox2.Text = TextBox1.Text
    	End Sub
    	Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    		TextBox3.Text = TextBox1.Text
    	End Sub
    	Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    		TextBox4.Text = TextBox1.Text
    	End Sub
    End Class


    Regards Les, Livingston, Scotland


    • Edited by leshay Thursday, July 11, 2019 8:20 PM
    Thursday, July 11, 2019 8:19 PM
  • Hi Les:

    Thanks for your reply. I have two tab pages. Page 1 has primary info and page 2 has secondary info.

    Sometimes I will be viewing page 1 and I will invoke a subroutine that requires a data item that is 

    displayed on page 2. I think that the data maybe doesn't appear in the page 2 textbox unless I

    click on tabpage 2 and the subroutine just can't find the data item. I hope I explained my problem

    better this time. Thanks.


    Thursday, July 11, 2019 9:39 PM
  • Hi

    I can't reproduce the issue here.

    As the code I posted shows, the TextBoxes are invoked by their name in the same way as if they were on the same form/page etc and all work fine here.

    Show the code that 'fails'.


    Regards Les, Livingston, Scotland

    Thursday, July 11, 2019 10:03 PM
  • Hi,

    Button1 assigns a value to the Textbox in Tabpage2, and Button2 gets the Textbox value in Tabpage2.

    Public Class Form1
    
        Private Sub TabPage2_Click(sender As Object, e As EventArgs) Handles TabPage2.Click
            Tabpage2TextBox.Text = "1"
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            TabPage2_Click(Nothing, Nothing)
        End Sub
    
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            Tabpage1TextBox.Text = Tabpage2TextBox.Text
        End Sub
    End Class

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Friday, July 12, 2019 1:56 AM
    Moderator
  • Hi:

    Thanks both for your replies. I guess my explanation just didn't cut it. I will try again.

    I have a form with two tabpages. Both tabpages have textboxes that are populated

    by a bindingsource that is bound to a datatable. There is a textbox on tabpage2 that

    has a value that is needed at times for a process. The thing is, that textbox on tabpage2

    does not get populated unless tabpage2 is activated. I know that if I place that textbox

    on tabpage1 my problem would be solved but I do not want it on tabpage1. Is there a

    way to have tabpage2 textboxes populate without the tabpage being active?

    Friday, July 12, 2019 11:19 PM
  • Hi

    How do you know it doesn't get populated if the TabPage isn't activated? If you open the TabPage to look, then it will be populated. If you don't open the TabPage to look then it could be populated or not (Schrödinger?)

    Anyway, looks like a simple way to do it would be to set up another Label (say) on the TabPage where you need the value and bind it to the same source as the TextBox on the other TabPage. Then .Visible = False. Doing that would make it available on the same TabPage.


    Regards Les, Livingston, Scotland

    Saturday, July 13, 2019 12:31 AM
  • Hi Les:

    Schrödinger's cat. You watch "Big Bang" too?

    Yes, I was hoping to avoid that approach but it would save time trying 

    to figure out a more eloquent approach.

    Thanks

    Saturday, July 13, 2019 8:21 PM