• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 608
  • Last Modified:

How to make a same component visible from two Tab Pages of a Tab control

Hi Experts,

I want to be able to make the same DataGridView component visible no matter which Tab Page is selected on a Tab control. The idea is to use the same DataGridView but using a different column layout.

I could do this with VB6, but with VB.NET it appears that the DataGridView component is a member of one Tab Page only.

The attached graphics show what I have in mind.

1 Solution
Mike TomlinsonMiddle School Assistant TeacherCommented:
"... but with VB.NET it appears that the DataGridView component is a member of one Tab Page only."

That's correct.  A control can only have ONE container.  When you add a control to a container, though, it will automatically be removed from its previous container.

Thus you could do:
    Private Sub TabControl1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
        ' Move the DataGridView to the Current Tab:

        ' Change the DataGridView somehow:
        Select Case TabControl1.SelectedIndex
            Case 0
                ' configure the columns for tab 0

            Case 1
                ' configure the columns for tab 1

            Case 2
                ' configure the columns for tab 2

        End Select
    End Sub

Open in new window

LeighWardleAuthor Commented:
Brilliant, thanks, your mind isn't that idle is it?

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now