How can add new tab on a tab page control by clicking a child node in a treeview?

Recommended Answers

Hi,

You need to declare your tabpage as the new one, give this page a name and add that new tabpage to the Tabpagecontrol.
Add this code to the Listview selectedindexchange event.

Try this and show us your codes.

Jump to Post

Hi,

You can try this;

TabControl1.TabPages.Item("TabPage2")
Jump to Post

All 6 Replies

Hi,

You need to declare your tabpage as the new one, give this page a name and add that new tabpage to the Tabpagecontrol.
Add this code to the Listview selectedindexchange event.

Try this and show us your codes.

I think i got it but my problem is that. The form inside the tab page are movable. And when i click the node to add pages, it does not focuses on the page i selected. What i mean is that if i clicked the "Borrow" child node. The Tab Page named "Borrow" should be selected.

These are my codes.

Public Class frmMain

    Private Sub treeviewMain_NodeMouseDoubleClick(sender As Object, e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles treeviewMain.NodeMouseDoubleClick

        Dim page As Integer = tabMain.TabPages.Count
        Dim tabpage As New TabPage
        tabpage.Text = treeviewMain.SelectedNode.Text.ToString()

        If (treeviewMain.SelectedNode.Text.ToString() = "Return") Then

            tabMain.TabPages.Add(tabpage)
            Dim frm As New frmReturn
            frm.TopLevel = False
            frm.Parent = tabMain.TabPages(page)
            frm.Show()

        ElseIf (treeviewMain.SelectedNode.Text.ToString() = "Borrow") Then

            tabMain.TabPages.Add(tabpage)
            Dim frm As New frmBorrow
            frm.TopLevel = False
            frm.Parent = tabMain.TabPages(page)
            frm.Show()

        ElseIf (treeviewMain.SelectedNode.Text.ToString() = "OPAC") Then

            tabMain.TabPages.Add(tabpage)
            Dim frm As New frmOPAC
            frm.TopLevel = False
            frm.Parent = tabMain.TabPages(page)
            frm.Show()

        End If
    End Sub
End Class

THANKS!!

Hi,

You can try this;

TabControl1.TabPages.Item("TabPage2")

Double post.

I believe this has already been asked by you here

Sorry. I have to delete this. BTW thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.