Load tab control using treeview childnode


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 12 of 12

Thread: Load tab control using treeview childnode

  1. #1
    Join Date
    Feb 2008
    Posts
    28

    Load tab control using treeview childnode

    Hi,

    I am in desperate of help. I am working with visual basic .net 2005. My interface is made from treeview control and tab control. I set the tab control visibility to false.

    The big question here is how do I load the tab control using the treeview control child node.

    Thanks

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    I don't understand the question. Can you describe in more detail what you want to do?
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Feb 2008
    Posts
    28
    I have a treeview control on my form with a list of tree nodes created on the left hand side of the interface. On the right hand is the tab control with current properties visibility set to false. I want to load the tab control upon selecting a child node of the tree.

    I found the following code from this website but I am having problem running it...

    Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
    Dim node As TreeNode = CType(sender, Windows.Forms.TreeView).SelectedNode
    If node = ???? Then
    TabControl1.Visible = True
    End If
    End Sub

    The child node name is 'Enter/Adjust Customer' when i put this in the program there is error of overload resolution. I know I have miss out stuff but clearly I am clueless as I am new to programming.

    Please help...

  4. #4
    Join Date
    Feb 2008
    Posts
    28

    Using multiple treenodes to load different tabcontrol

    Hi,

    I am facing a new problem with the tabcontrol again. This time I want to use separate treeview nodes to load separate tabcontrols. The following is my code.

    Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
    Dim Node As TreeNode = CType(sender, Windows.Forms.TreeView).SelectedNode
    AddCustomer.Visible = (Node.Name.ToString = "Enter/Adjust Customer")
    TabControl1.Visible = (Node.Name.ToString = "Delete Customer")
    TabControl2.Visible = (Node.Name.ToString = "Enter/Adjust Payemt")
    End Sub

    This part of the statement 'AddCustomer.Visible = (Node.Name.ToString = "Enter/Adjust Customer") ' works just fine, but when I try to add another tabcontrol and use another node to call it, it just remain blank.

    When I layer the tabcontrol on top of another and it also refuse to dock fully on the whole splittercontainer.

    I am close to tears trying to solve it cause I need to create many tabcontrols to connect to many treenodes.

    Please help!!

  5. #5
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    When I try to add another tabcontrol and use another node to call it, it just remain blank.
    Please post the code that isn't working.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  6. #6
    Join Date
    Feb 2008
    Posts
    28

    Re: Load tab control using treeview childnode

    This are the 2 lines that is not working. When I debug it, it does not contain any error.

    TabControl1.Visible = (Node.Name.ToString = "Delete Customer")
    TabControl2.Visible = (Node.Name.ToString = "Enter/Adjust Paymemt")

    Will it be because I am not allow to layer different tabcontrol on the same form??

  7. #7
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    It may be because those tabs are contained inside another tab control. Make sure you paste them directly onto the form and not inside another tab.

    Here's how I would do it (I'm using Panels, but this technique should work just as well with Tabs):

    1. Add the desired containers (Tabs, Panels) to the Form at design time. Set their Visible properties to False.
    2. At runtime, set the Tag property of each TreeNode to its associated Tab/Panel:
    Code:
        Private Sub Form1_Load(ByVal sender As Object, _
            ByVal e As System.EventArgs) Handles Me.Load
    
            With TreeView1.Nodes.Item("Root")
                .Nodes.Item("EnterCustomer").Tag = Panel1
                .Nodes.Item("DeleteCustomer").Tag = Panel2
                .Nodes.Item("EnterPayment").Tag = Panel3
            End With
    
        End Sub
    3. When the user clicks on a node, hide the previously-visible container and show the container associated with the selected node:
    Code:
    Public Class Form1
        Private PreviousPanel As Panel
    
        Private Sub TreeView1_AfterSelect(ByVal sender As Object, _
            ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
    
            If PreviousPanel IsNot Nothing Then
                PreviousPanel.Visible = False
            End If
    
            If e.Node.Tag IsNot Nothing Then
                Dim ActivePanel As Panel = CType(e.Node.Tag, Panel)
                ActivePanel.Visible = True
                ActivePanel.Dock = DockStyle.Fill
                PreviousPanel = ActivePanel
            End If
    
        End Sub
    
    End Class
    Last edited by Phil Weber; 02-21-2008 at 06:59 PM.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  8. #8
    Join Date
    Feb 2008
    Posts
    28
    I converted the code you have given me from panel to tabcontrol as below:
    Public Class Form1
    Private PreviousTab As TabControl

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    With TreeView1.Nodes.Item("AdminMenu")
    .Nodes.Item("AddCustomer").Tag = TabAddCust
    .Nodes.Item("DeleteCust").Tag = TabDeleteCust
    End With

    End Sub

    Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
    If PreviousTab IsNot Nothing Then
    PreviousTab.Visible = False
    End If
    If e.Node.Tag IsNot Nothing Then
    Dim ActiveTab As TabControl = CType(e.Node.Tag, TabControl)
    ActiveTab.Visible = True
    ActiveTab.Dock = DockStyle.Fill
    PreviousTab = ActiveTab
    End If

    I face an error of NullReferenceException was unhandled when I run the program. The part of the code that face the problem is as below

    .Nodes.Item("AddCustomer").Tag = TabAddCust
    .Nodes.Item("DeleteCust").Tag = TabDeleteCust

    Please help!!

    Thanks for the advice of not docking the tabcontrol on top of another as that have solved my problem.

  9. #9
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Put this code inside your Form1 class and run it. Post the output that appears in the debug window:
    Code:
        Private Sub Form1_Load(ByVal sender As Object, _ 
            ByVal e As System.EventArgs) Handles Me.Load
            ListNodes(TreeView1.Nodes(0))
        End Sub
    
        Private Sub ListNodes(ByVal StartNode As TreeNode)
            Debug.WriteLine(StartNode.Name)
            For Each n As TreeNode In StartNode.Nodes
                ListNodes(n)
            Next
        End Sub
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  10. #10
    Join Date
    Feb 2008
    Posts
    28

    Re: Load tab control using treeview childnode

    I have inserted the code.

    The same error of NullReferenceException was unhandled happens to the following code. The troubleshooting tips given is to use the "new" keyword to create object instance

    .Nodes.Item("AddCustomer").Tag = TabAddCust
    .Nodes.Item("DeleteCust").Tag = TabDeleteCust

  11. #11
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Yes, you need to comment out those two lines. I want you to run the code I posted and post the output.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  12. #12
    Join Date
    Feb 2008
    Posts
    28

    Re: Load tab control using treeview childnode

    I have done what you told me. There is no output on the debug window.

    Just when there are this 2 lines available during running time it will be highlighted in yellow warning with the message I mention earlier written.

    The following is the codes I used
    Code:
    Public Class Form1
    Private PreviousTab As TabControl
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load
            ListNodes(TreeView1.Nodes(0))
            With TreeView1.Nodes.Item("AdminMenu")
                .Nodes.Item("AddCustomer").Tag = TabAddCust
                .Nodes.Item("DeleteCust").Tag = TabDeleteCust
            End With
        End Sub
        Private Sub ListNodes(ByVal StartNode As TreeNode)
            Debug.WriteLine(StartNode.Name)
            For Each n As TreeNode In StartNode.Nodes
                ListNodes(n)
            Next
    End Sub
    
    Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
            If PreviousTab IsNot Nothing Then
                PreviousTab.Visible = False
            End If
            If e.Node.Tag IsNot Nothing Then
                Dim ActiveTab As TabControl = CType(e.Node.Tag, TabControl)
                ActiveTab.Visible = True
                ActiveTab.Dock = DockStyle.Fill
                PreviousTab = ActiveTab
            End If
        End Sub
    Last edited by Hack; 02-22-2008 at 07:55 AM. Reason: Added Code Tags

Similar Threads

  1. Replies: 1
    Last Post: 09-07-2005, 01:16 AM
  2. Replies: 1
    Last Post: 07-05-2005, 07:16 AM
  3. Image Edit Control
    By Sinni in forum VB Classic
    Replies: 1
    Last Post: 03-06-2003, 05:50 PM
  4. Replies: 0
    Last Post: 03-23-2002, 03:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center