Hi VBForums,
Often I find myself in the need of a treeview panel selector, so I created a new custom control and added 2 panels, and added a treeview to one of them (Panel 1). I docked Panel1 to the left of my user control, and set the docking on the other one (Panel2) to Fill.
Now here is my question...I want to create a new panel for each treenode in my treeview when the usercontrol loads, and add it to Panel2. This is what I'm doing currently.
Private Sub TreeViewPanelSelector_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
For Each n As TreeNode In TreeView1.Nodes
Dim p As New Panel
p.BackColor = Color.Cyan
p.Dock = DockStyle.Fill
Dim lbl As New Label
lbl.Text = n.Text
p.Controls.Add(lbl)
Panel2.Controls.Add(p)
Next
End Sub
It works...but what would be a better solution, because I'd rather be designing the panels for each treenode with the designer for each individual application I use this in. Since the panels will be different for each application, I'm wondering if this will even save me any time at all :-\
Often I find myself in the need of a treeview panel selector, so I created a new custom control and added 2 panels, and added a treeview to one of them (Panel 1). I docked Panel1 to the left of my user control, and set the docking on the other one (Panel2) to Fill.
Now here is my question...I want to create a new panel for each treenode in my treeview when the usercontrol loads, and add it to Panel2. This is what I'm doing currently.
Private Sub TreeViewPanelSelector_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
For Each n As TreeNode In TreeView1.Nodes
Dim p As New Panel
p.BackColor = Color.Cyan
p.Dock = DockStyle.Fill
Dim lbl As New Label
lbl.Text = n.Text
p.Controls.Add(lbl)
Panel2.Controls.Add(p)
Next
End Sub
It works...but what would be a better solution, because I'd rather be designing the panels for each treenode with the designer for each individual application I use this in. Since the panels will be different for each application, I'm wondering if this will even save me any time at all :-\