-
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
-
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!
-
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...
-
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!!
-
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!
-
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??
-
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 05: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!
-
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.
-
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!
-
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
-
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!
-
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 06:55 AM.
Reason: Added Code Tags
Similar Threads
-
Replies: 1
Last Post: 09-07-2005, 12:16 AM
-
By Magdalene in forum ASP.NET
Replies: 1
Last Post: 07-05-2005, 06:16 AM
-
By Sinni in forum VB Classic
Replies: 1
Last Post: 03-06-2003, 04:50 PM
-
By Judie in forum VB Classic
Replies: 0
Last Post: 03-23-2002, 02: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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks