Run sub procedure for selected TreeViewNode in vb.net

I've TreeView with checkbox nodes, each node's childnode is representing a sub procedure feature that will perform if this option checked.

000479.jpg
I put them in one single button, but i had to check all of them individually but this is a bit hard way to define each of them because it's hard to handle.

Is there anyway like to create a dictionary with this child nodes and sub procedures.

 Public Shared Sub RunCheck(ByVal mdl As IScrModel)

            Dim tView As TreeView = GUI.treCheckListMain
            Dim dgView As DataGridView = GUI.dgvCheckInfo
            dgView.Rows.Clear()

            For Each nodeParent As TreeNode In tView.Nodes
                For Each nodeChild As TreeNode In nodeParent.Nodes
                    If nodeChild.Checked = True Then
                        dgView.Rows.Add(nodeParent.Text, nodeChild.Text, "In queue")
                    End If
                Next
            Next

            If tView.Nodes.Item("nodBody").Nodes.Item("nodBodyComp").Checked = True Then
                Dim rowIndex As Integer = FindRowDgv(tView.Nodes.Item("nodBody").Text, tView.Nodes.Item("nodBody").Nodes.Item("nodBodyComp").Text)
                Try
                    StyleStatus(rowIndex, "Performing", Color.Yellow)
                    Body.ListBodies(mdl, GUI.GetRecursive(GUI.cboCheckBodyComputed_recur.SelectedIndex), GUI.dgvCheckBodyComputed)
                    StyleStatus(rowIndex, "Finished", Color.Green)
                Catch ex As Exception
                    StyleStatus(rowIndex, "Error Occured", Color.Red)
                    Tools.OutputLog.Print(Tools.OutputLog.Type.ERR, ex.Message)
                End Try

            End If
            If tView.Nodes.Item("nodMarker").Nodes.Item("nodMarkerComp").Checked = True Then
                Dim rowIndex As Integer = FindRowDgv(tView.Nodes.Item("nodMarker").Text, tView.Nodes.Item("nodMarker").Nodes.Item("nodMarkerComp").Text)
                Try
                    StyleStatus(rowIndex, "Performing", Color.Yellow)
                    Marker.ListMarkers(mdl, GUI.GetRecursive(GUI.cboCheckMarkerPosition_recur.SelectedIndex), GUI.dgvCheckMarkerPosition)
                    StyleStatus(rowIndex, "Finished", Color.Green)
                Catch ex As Exception
                    StyleStatus(rowIndex, "Error Occured", Color.Red)
                    Tools.OutputLog.Print(Tools.OutputLog.Type.ERR, ex.Message)
                End Try

            End If
            If tView.Nodes.Item("nodSubvar").Nodes.Item("nodSubvarPa").Checked = True Then
                Dim rowIndex As Integer = FindRowDgv(tView.Nodes.Item("nodSubvar").Text, tView.Nodes.Item("nodSubvar").Nodes.Item("nodSubvarPa").Text)
                Try
                    StyleStatus(rowIndex, "Performing", Color.Yellow)
                    Subvar.ListSubvarsPA(mdl, GUI.GetRecursive(GUI.cboCheckSubvarPa_recur.SelectedIndex), GUI.GetSubstr(GUI.cboCheckSubvarPa_substr.SelectedIndex), GUI.GetEval(GUI.cboCheckSubvarPa_eval.SelectedIndex), GUI.dgvCheckSubvarPa)
                    StyleStatus(rowIndex, "Finished", Color.Green)
                Catch ex As Exception
                    StyleStatus(rowIndex, "Error Occured", Color.Red)
                    Tools.OutputLog.Print(Tools.OutputLog.Type.ERR, ex.Message)

                End Try
            End If
            If tView.Nodes.Item("nodSubvar").Nodes.Item("nodSubvarHp").Checked = True Then
                Dim rowIndex As Integer = FindRowDgv(tView.Nodes.Item("nodSubvar").Text, tView.Nodes.Item("nodSubvar").Nodes.Item("nodSubvarHp").Text)
                Try
                    StyleStatus(rowIndex, "Performing", Color.Yellow)
                    Subvar.ListSubvarsHP(mdl, GUI.GetRecursive(GUI.cboCheckSubvarHp_recur.SelectedIndex), GUI.GetSubstr(GUI.cboCheckSubvarHp_substr.SelectedIndex), GUI.GetEval(GUI.cboCheckSubvarHp_eval.SelectedIndex), GUI.dgvCheckSubvarHp)
                    StyleStatus(rowIndex, "Finished", Color.Green)
                Catch ex As Exception
                    StyleStatus(rowIndex, "Error Occured", Color.Red)
                    Tools.OutputLog.Print(Tools.OutputLog.Type.ERR, ex.Message)

                End Try
            End If
            If tView.Nodes.Item("nodSubvar").Nodes.Item("nodSubvarSens").Checked = True Then
                Dim rowIndex As Integer = FindRowDgv(tView.Nodes.Item("nodSubvar").Text, tView.Nodes.Item("nodSubvar").Nodes.Item("nodSubvarSens").Text)
                StyleStatus(rowIndex, "Not Active Yet", Color.Orange)
            End If
            If tView.Nodes.Item("nodSubvar").Nodes.Item("nodSubvarMp").Checked = True Then
                Dim rowIndex As Integer = FindRowDgv(tView.Nodes.Item("nodSubvar").Text, tView.Nodes.Item("nodSubvar").Nodes.Item("nodSubvarMp").Text)
                Try
                    StyleStatus(rowIndex, "Performing", Color.Yellow)
                    Subvar.ListSubvarsMP(mdl, GUI.GetRecursive(GUI.cboCheckSubvarMp_recur.SelectedIndex), GUI.GetSubstr(GUI.cboCheckSubvarMp_substr.SelectedIndex), GUI.GetEval(GUI.cboCheckSubvarMp_eval.SelectedIndex), GUI.dgvCheckSubvarMp)
                    StyleStatus(rowIndex, "Finished", Color.Green)
                Catch ex As Exception
                    StyleStatus(rowIndex, "Error Occured", Color.Red)
                    Tools.OutputLog.Print(Tools.OutputLog.Type.ERR, ex.Message)

                End Try
            End If
            If tView.Nodes.Item("nodSubvar").Nodes.Item("nodSubvarFe").Checked = True Then
                Dim rowIndex As Integer = FindRowDgv(tView.Nodes.Item("nodSubvar").Text, tView.Nodes.Item("nodSubvar").Nodes.Item("nodSubvarFe").Text)
                StyleStatus(rowIndex, "Not Active Yet", Color.Orange)
            End If
            If tView.Nodes.Item("nodSubvar").Nodes.Item("nodSubvar3d").Checked = True Then
                Dim rowIndex As Integer = FindRowDgv(tView.Nodes.Item("nodSubvar").Text, tView.Nodes.Item("nodSubvar").Nodes.Item("nodSubvar3d").Text)
                StyleStatus(rowIndex, "Not Active Yet", Color.Orange)
            End If
            If tView.Nodes.Item("nodForce").Nodes.Item("nodForce43").Checked = True Then
                Dim rowIndex As Integer = FindRowDgv(tView.Nodes.Item("nodForce").Text, tView.Nodes.Item("nodForce").Nodes.Item("nodForce43").Text)
                Try
                    StyleStatus(rowIndex, "Performing", Color.Yellow)
                    Force.ListForce43(mdl, GUI.GetRecursive(GUI.cboCheckForce43_recur.SelectedIndex), GUI.dgvCheckForce43)
                    StyleStatus(rowIndex, "Finished", Color.Green)
                Catch ex As Exception
                    StyleStatus(rowIndex, "Error Occured", Color.Red)
                    Tools.OutputLog.Print(Tools.OutputLog.Type.ERR, ex.Message)

                End Try
            End If
            If tView.Nodes.Item("nodForce").Nodes.Item("nodForce18").Checked = True Then
                Dim rowIndex As Integer = FindRowDgv(tView.Nodes.Item("nodForce").Text, tView.Nodes.Item("nodForce").Nodes.Item("nodForce18").Text)
                Try
                    StyleStatus(rowIndex, "Performing", Color.Yellow)
                    Force.ListForce18(mdl, GUI.GetRecursive(GUI.cboCheckForce18_recur.SelectedIndex), GUI.dgvCheckForce18)
                    StyleStatus(rowIndex, "Finished", Color.Green)
                Catch ex As Exception
                    StyleStatus(rowIndex, "Error Occured", Color.Red)
                    Tools.OutputLog.Print(Tools.OutputLog.Type.ERR, ex.Message)

                End Try
            End If
            If tView.Nodes.Item("nodForce").Nodes.Item("nodForce4").Checked = True Then
                Dim rowIndex As Integer = FindRowDgv(tView.Nodes.Item("nodForce").Text, tView.Nodes.Item("nodForce").Nodes.Item("nodForce4").Text)
                Try
                    StyleStatus(rowIndex, "Performing", Color.Yellow)
                    Force.ListForce4(mdl, GUI.GetRecursive(GUI.cboCheckForce18_recur.SelectedIndex), GUI.dgvCheckForce18)
                    StyleStatus(rowIndex, "Finished", Color.Green)
                Catch ex As Exception
                    StyleStatus(rowIndex, "Error Occured", Color.Red)
                    Tools.OutputLog.Print(Tools.OutputLog.Type.ERR, ex.Message)

                End Try
            End If
            If tView.Nodes.Item("nodForceOut").Nodes.Item("nodForceOutDist").Checked = True Then
                Dim rowIndex As Integer = FindRowDgv(tView.Nodes.Item("nodForceOut").Text, tView.Nodes.Item("nodForceOut").Nodes.Item("nodForceOutDist").Text)
                Try
                    StyleStatus(rowIndex, "Performing", Color.Yellow)
                    ForceOut.ListForceOutDist(mdl, GUI.GetRecursive(GUI.cboCheckForceOutDist_recur.SelectedIndex), GUI.dgvCheckForceOutDist)
                    StyleStatus(rowIndex, "Finished", Color.Green)
                Catch ex As Exception
                    StyleStatus(rowIndex, "Error Occured", Color.Red)
                    Tools.OutputLog.Print(Tools.OutputLog.Type.ERR, ex.Message)
                End Try
            End If
            If tView.Nodes.Item("nodForceOut").Nodes.Item("nodForceOut43").Checked = True Then
                Dim rowIndex As Integer = FindRowDgv(tView.Nodes.Item("nodForceOut").Text, tView.Nodes.Item("nodForceOut").Nodes.Item("nodForceOut43").Text)
                Try
                    StyleStatus(rowIndex, "Performing", Color.Yellow)
                    ForceOut.ListForceOut43(mdl, GUI.GetRecursive(GUI.cboCheckForceOut43_recur.SelectedIndex), GUI.dgvCheckForceOut43)
                    StyleStatus(rowIndex, "Finished", Color.Green)
                Catch ex As Exception
                    StyleStatus(rowIndex, "Error Occured", Color.Red)
                    Tools.OutputLog.Print(Tools.OutputLog.Type.ERR, ex.Message)
                End Try

            End If
            If tView.Nodes.Item("nodForceOut").Nodes.Item("nodForceOut18").Checked = True Then
                Dim rowIndex As Integer = FindRowDgv(tView.Nodes.Item("nodForceOut").Text, tView.Nodes.Item("nodForceOut").Nodes.Item("nodForceOut18").Text)
                Try
                    StyleStatus(rowIndex, "Performing", Color.Yellow)
                    ForceOut.ListForceOut18(mdl, GUI.GetRecursive(GUI.cboCheckForceOut18_recur.SelectedIndex), GUI.dgvCheckForceOut18)
                    StyleStatus(rowIndex, "Finished", Color.Green)
                Catch ex As Exception
                    StyleStatus(rowIndex, "Error Occured", Color.Red)
                    Tools.OutputLog.Print(Tools.OutputLog.Type.ERR, ex.Message)
                End Try
            End If
            If tView.Nodes.Item("nodForceOut").Nodes.Item("nodForceOut4").Checked = True Then
                Dim rowIndex As Integer = FindRowDgv(tView.Nodes.Item("nodForceOut").Text, tView.Nodes.Item("nodForceOut").Nodes.Item("nodForceOut4").Text)
                Try
                    StyleStatus(rowIndex, "Performing", Color.Yellow)
                    ForceOut.ListForceOut4(mdl, GUI.GetRecursive(GUI.cboCheckForceOut4_recur.SelectedIndex), GUI.dgvCheckForceOut4)
                    StyleStatus(rowIndex, "Finished", Color.Green)
                Catch ex As Exception
                    StyleStatus(rowIndex, "Error Occured", Color.Red)
                    Tools.OutputLog.Print(Tools.OutputLog.Type.ERR, ex.Message)

                End Try

            End If
            If tView.Nodes.Item("nodIfctn").Nodes.Item("nodIfctnBase").Checked = True Then
                Dim rowIndex As Integer = FindRowDgv(tView.Nodes.Item("nodIfctn").Text, tView.Nodes.Item("nodIfctn").Nodes.Item("nodIfctnBase").Text)
                Try
                    StyleStatus(rowIndex, "Performing", Color.Yellow)
                    Ifctn.ListIfctn(mdl, GUI.GetRecursive(GUI.cboCheckIfctnBase_recur.SelectedIndex), GUI.dgvCheckIfctnBase)
                    StyleStatus(rowIndex, "Finished", Color.Green)
                Catch ex As Exception
                    StyleStatus(rowIndex, "Error Occured", Color.Red)
                    Tools.OutputLog.Print(Tools.OutputLog.Type.ERR, ex.Message)

                End Try

            End If
            If tView.Nodes.Item("nodComm").Nodes.Item("nodCommSender").Checked = True Then
                Dim rowIndex As Integer = FindRowDgv(tView.Nodes.Item("nodComm").Text, tView.Nodes.Item("nodComm").Nodes.Item("nodCommSender").Text)
                Try
                    StyleStatus(rowIndex, "Performing", Color.Yellow)
                    Sender.ListSender(mdl, GUI.GetRecursive(GUI.cboCheckSender_recur.SelectedIndex), GUI.dgvCheckCommSender)
                    StyleStatus(rowIndex, "Finished", Color.Green)
                Catch ex As Exception
                    StyleStatus(rowIndex, "Error Occured", Color.Red)
                    Tools.OutputLog.Print(Tools.OutputLog.Type.ERR, ex.Message)

                End Try

            End If
            If tView.Nodes.Item("nodComm").Nodes.Item("nodCommReceiver").Checked = True Then
                Dim rowIndex As Integer = FindRowDgv(tView.Nodes.Item("nodComm").Text, tView.Nodes.Item("nodComm").Nodes.Item("nodCommReceiver").Text)
                Try
                    StyleStatus(rowIndex, "Performing", Color.Yellow)
                    Receiver.ListReceiver(mdl, GUI.GetRecursive(GUI.cboCheckReceiver_recur.SelectedIndex), GUI.dgvCheckCommReceiver)
                    StyleStatus(rowIndex, "Finished", Color.Green)
                Catch ex As Exception
                    StyleStatus(rowIndex, "Error Occured", Color.Red)
                    Tools.OutputLog.Print(Tools.OutputLog.Type.ERR, ex.Message)

                End Try
            End If

            If tView.Nodes.Item("nodExpression").Nodes.Item("nodExpressionCutForce").Checked = True Then
                Dim rowIndex As Integer = FindRowDgv(tView.Nodes.Item("nodExpression").Text, tView.Nodes.Item("nodExpression").Nodes.Item("nodExpressionCutForce").Text)
                Try
                    StyleStatus(rowIndex, "Performing", Color.Yellow)
                    Expressions.ListExpressionCutforce(mdl, GUI.GetRecursive(GUI.cboCheckExpressionCutForce_recur.SelectedIndex), GUI.GetSubstr(GUI.cboCheckExpressionCutForce_substr.SelectedIndex), GUI.dgvCheckExpressionCutForce)
                    StyleStatus(rowIndex, "Finished", Color.Green)
                Catch ex As Exception
                    StyleStatus(rowIndex, "Error Occured", Color.Red)
                    Tools.OutputLog.Print(Tools.OutputLog.Type.ERR, ex.Message)
                End Try
            End If

            If tView.Nodes.Item("nodSolve").Nodes.Item("nodSolvePreload").Checked = True Then
                Dim rowIndex As Integer = FindRowDgv(tView.Nodes.Item("nodSolve").Text, tView.Nodes.Item("nodSolve").Nodes.Item("nodSolvePreload").Text)
                Try
                    StyleStatus(rowIndex, "Performing", Color.Yellow)
                    Preload.ListPreload(mdl, GUI.dgvCheckSolvePreld)
                    StyleStatus(rowIndex, "Finished", Color.Green)
                Catch ex As Exception
                    StyleStatus(rowIndex, "Error Occured", Color.Red)
                    Tools.OutputLog.Print(Tools.OutputLog.Type.ERR, ex.Message)

                End Try

            End If
            If tView.Nodes.Item("nodSolve").Nodes.Item("nodSolveEqui").Checked = True Then
                Dim rowIndex As Integer = FindRowDgv(tView.Nodes.Item("nodSolve").Text, tView.Nodes.Item("nodSolve").Nodes.Item("nodSolveEqui").Text)
                Try
                    StyleStatus(rowIndex, "Performing", Color.Yellow)
                    Equilibrium.ListEquilibrium(mdl, GUI.dgvCheckSolveEq)
                    StyleStatus(rowIndex, "Finished", Color.Green)
                Catch ex As Exception
                    StyleStatus(rowIndex, "Error Occured", Color.Red)
                    Tools.OutputLog.Print(Tools.OutputLog.Type.ERR, ex.Message)

                End Try

            End If
            If tView.Nodes.Item("nodSolve").Nodes.Item("nodSolveEigen").Checked = True Then
                Dim rowIndex As Integer = FindRowDgv(tView.Nodes.Item("nodSolve").Text, tView.Nodes.Item("nodSolve").Nodes.Item("nodSolveEigen").Text)
                Try
                    StyleStatus(rowIndex, "Performing", Color.Yellow)
                    Eigenvalue.ListEigenvalue(Globals.SpckModel, GUI.dgvCheckSolveEva)
                    StyleStatus(rowIndex, "Finished", Color.Green)
                Catch ex As Exception
                    StyleStatus(rowIndex, "Error Occured", Color.Red)
                    Tools.OutputLog.Print(Tools.OutputLog.Type.ERR, ex.Message)

                End Try
            End If
            If tView.Nodes.Item("nodNaming").Nodes.Item("nodNamingSpck").Checked = True Then
                Dim rowIndex As Integer = FindRowDgv(tView.Nodes.Item("nodNaming").Text, tView.Nodes.Item("nodNaming").Nodes.Item("nodNamingSpck").Text)
                StyleStatus(rowIndex, "Not Active Yet", Color.Orange)
            End If
            If tView.Nodes.Item("nodNaming").Nodes.Item("nodNamingCad").Checked = True Then
                Dim rowIndex As Integer = FindRowDgv(tView.Nodes.Item("nodNaming").Text, tView.Nodes.Item("nodNaming").Nodes.Item("nodNamingCad").Text)
                StyleStatus(rowIndex, "Not Active Yet", Color.Orange)
            End If
            If tView.Nodes.Item("nodNaming").Nodes.Item("nodNamingFbi").Checked = True Then
                Dim rowIndex As Integer = FindRowDgv(tView.Nodes.Item("nodNaming").Text, tView.Nodes.Item("nodNaming").Nodes.Item("nodNamingFbi").Text)
                StyleStatus(rowIndex, "Not Active Yet", Color.Orange)
            End If
        End Sub

Open in new window

HakanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ste5anSenior DeveloperCommented:
Well, it depends on the control. Look into the events list. There should be node click events as well as node selected events.

From the OO perspective:
[..] representing a sub procedure feature that will perform if this option checked [..]
Take a look at the template and the strategy pattern first. Also take look at the command and the chain of responsibility pattern.
HakanAuthor Commented:
Sorry, I don't understand clearly. I have some checks as my tool's feature. User selecting which of the checks will perform (listed on treeview) after user click the run button it's looking for the node is checked or not after that if it's checked it's calling specific procedure for that node
ste5anSenior DeveloperCommented:
Your actual problem is easily solved by you by looking at the events of your control. Normally tree view controls have events like node clicked, node select etc. Here you have direct access to the node involved.



The rest was a comment about your coding approach involving a lot of guessing: The tree view (UI) should not have any coupling to the executed functionality (logic). It is just the UI for configuring your tool.
[..] a sub procedure feature [..]
In this context this means that you should look into some default approaches in Object Oriented Programming. The patterns I mentioned. Cause depending on these, the problem maybe simply solved by binding your "features" directly to the tree view.
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

HakanAuthor Commented:
How is it possible to bind that one procedure to TreeViewNode? Could you please give an example
ste5anSenior DeveloperCommented:
E.g.

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        TreeView1.Nodes.Add(DirectCast(New StrategyA("A"), TreeNode))
        TreeView1.Nodes.Add(DirectCast(New StrategyA("B"), TreeNode))
        TreeView1.Nodes.Add(DirectCast(New StrategyB("C"), TreeNode))
        TreeView1.Nodes.Add(DirectCast(New StrategyB("D"), TreeNode))
    End Sub

    Private Sub TreeView1_DoubleClick(sender As Object, e As EventArgs) Handles TreeView1.DoubleClick
        Dim strategy As IStrategy = DirectCast(DirectCast(sender, TreeView).SelectedNode, IStrategy)
        strategy.Execute()
    End Sub
End Class

Public Interface IStrategy
    Sub Execute()
End Interface

Public Class StrategyA
    Inherits TreeNode
    Implements IStrategy

    Public Sub New(AText As String)
        Me.Text = AText
    End Sub

    Public Sub Execute() Implements IStrategy.Execute
        MessageBox.Show("A:" & Me.Text)
    End Sub
End Class

Public Class StrategyB
    Inherits TreeNode
    Implements IStrategy

    Public Sub New(AText As String)
        Me.Text = AText
    End Sub

    Public Sub Execute() Implements IStrategy.Execute
        MessageBox.Show("B:" & Me.Text)
    End Sub
End Class

Open in new window

Caveat: this is a really simplified sample.

EDIT: Changed order to support VS designer.
HakanAuthor Commented:
Picture1.png
I need to clarify my side, i don't know how is your solution work but i have existing TreeViewNodes.

Like a below picture i'm checking  the node's check status and perform sub procedures according to this.

I've existing TreeViewNodes. Only i want
it_saigeDeveloperCommented:
I think this is what you are wanting to do:
Private Sub OnClick(sender As Object, e As EventArgs) Handles Button1.Click
    Dim selected = GetChildNodes(tView.Nodes).Where(Function(n) n.Checked AndAlso n.Parent IsNot Nothing)
    For Each node In selected
        Dim index = FindRowDgv(node.Parent.Text, node.Text)
        Try
            StyleStatus(index, "Performing", Color.Yellow)
            Select Case node.Parent.Name
                Case "nodBody"
                    Body.ListBodies(mdl, GUI.GetRecursive(GUI.cboCheckBodyComputed_recur.SelectedIndex), GUI.dgvCheckBodyComputed)
                Case "nodMarker"
                    Marker.ListMarkers(mdl, GUI.GetRecursive(GUI.cboCheckMarkerPosition_recur.SelectedIndex), GUI.dgvCheckMarkerPosition)
                Case "nodSubvar"
                    Select Case node.Name
                        Case "nodSubvarPa"
                            Subvar.ListSubvarsPA(mdl, GUI.GetRecursive(GUI.cboCheckSubvarPa_recur.SelectedIndex), GUI.GetSubstr(GUI.cboCheckSubvarPa_substr.SelectedIndex), GUI.GetEval(GUI.cboCheckSubvarPa_eval.SelectedIndex), GUI.dgvCheckSubvarPa)
                        Case "nodSubvarHp"
                            Subvar.ListSubvarsHP(mdl, GUI.GetRecursive(GUI.cboCheckSubvarHp_recur.SelectedIndex), GUI.GetSubstr(GUI.cboCheckSubvarHp_substr.SelectedIndex), GUI.GetEval(GUI.cboCheckSubvarHp_eval.SelectedIndex), GUI.dgvCheckSubvarHp)
                        Case "nodSubvarMp"
                            Subvar.ListSubvarsMP(mdl, GUI.GetRecursive(GUI.cboCheckSubvarMp_recur.SelectedIndex), GUI.GetSubstr(GUI.cboCheckSubvarMp_substr.SelectedIndex), GUI.GetEval(GUI.cboCheckSubvarMp_eval.SelectedIndex), GUI.dgvCheckSubvarMp)
                        Case "nodSubvarSens", "nodSubvarFe", "nodSubvar3d"
                            StyleStatus(rowIndex, "Not Active Yet", Color.Orange)
                            Continue For
                    End Select
                Case "nodForce"
                    Select Case node.Name
                        Case "nodForce43"
                            Force.ListForce43(mdl, GUI.GetRecursive(GUI.cboCheckForce43_recur.SelectedIndex), GUI.dgvCheckForce43)
                        Case "nodForce18"
                            Force.ListForce18(mdl, GUI.GetRecursive(GUI.cboCheckForce18_recur.SelectedIndex), GUI.dgvCheckForce18)
                        Case "nodForce4"
                            Force.ListForce4(mdl, GUI.GetRecursive(GUI.cboCheckForce18_recur.SelectedIndex), GUI.dgvCheckForce18)
                    End Select
                Case "nodForceOut"
                    Select Case node.Name
                        Case "nodForceOutDist"
                            ForceOut.ListForceOutDist(mdl, GUI.GetRecursive(GUI.cboCheckForceOutDist_recur.SelectedIndex), GUI.dgvCheckForceOutDist)
                        Case "nodForceOut43"
                            ForceOut.ListForceOut43(mdl, GUI.GetRecursive(GUI.cboCheckForceOut43_recur.SelectedIndex), GUI.dgvCheckForceOut43)
                        Case "nodForceOut18"
                            ForceOut.ListForceOut18(mdl, GUI.GetRecursive(GUI.cboCheckForceOut18_recur.SelectedIndex), GUI.dgvCheckForceOut18)
                        Case "nodForceOut4"
                            ForceOut.ListForceOut4(mdl, GUI.GetRecursive(GUI.cboCheckForceOut4_recur.SelectedIndex), GUI.dgvCheckForceOut4)
                    End Select
                Case "nodIfctn"
                    Ifctn.ListIfctn(mdl, GUI.GetRecursive(GUI.cboCheckIfctnBase_recur.SelectedIndex), GUI.dgvCheckIfctnBase)
                Case "nodComm"
                    Select Case node.Name
                        Case "nodCommSender"
                            Sender.ListSender(mdl, GUI.GetRecursive(GUI.cboCheckSender_recur.SelectedIndex), GUI.dgvCheckCommSender)
                        Case "nodCommReceiver"
                            Receiver.ListReceiver(mdl, GUI.GetRecursive(GUI.cboCheckReceiver_recur.SelectedIndex), GUI.dgvCheckCommReceiver)
                    End Select
                Case "nodExpression"
                    Expressions.ListExpressionCutforce(mdl, GUI.GetRecursive(GUI.cboCheckExpressionCutForce_recur.SelectedIndex), GUI.GetSubstr(GUI.cboCheckExpressionCutForce_substr.SelectedIndex), GUI.dgvCheckExpressionCutForce)
                Case "nodSolve"
                    Select Case node.Name
                        Case "nodSolvePreload"
                            Preload.ListPreload(mdl, GUI.dgvCheckSolvePreld)
                        Case "nodSolveEqui"
                            Equilibrium.ListEquilibrium(mdl, GUI.dgvCheckSolveEq)
                        Case "nodSolveEigen"
                            Eigenvalue.ListEigenvalue(Globals.SpckModel, GUI.dgvCheckSolveEva)
                    End Select
                Case "nodNaming"
                    Select Case node.Name
                        Case "nodNamingSpck", "nodNamingCad", "nodNamingFbi"
                            StyleStatus(rowIndex, "Not Active Yet", Color.Orange)
                            Continue For
                    End Select
            End Select
            StyleStatus(index, "Finished", Color.Green)
        Catch ex As Exception
            StyleStatus(index, "Error Occurred", Color.Red)
            Tools.OutputLog.Print(Tools.OutputLog.Type.ERR, ex.Message)
        End Try
    Next
End Sub

Open in new window

GetChildNodes is an extension in a Module -
Module Extensions
    <Extension>
    Public Iterator Function GetChildNodes(tree As TreeNodeCollection) As IEnumerable(Of TreeNode)
        For Each node In tree.OfType(Of TreeNode)
            Yield node
            For Each child In GetChildNodes(node.Nodes)
                Yield child
            Next
        Next
    End Function
End Module

Open in new window

That being said, ste5an's recommendation is the preferred route I would take.  I understand that you have a tree view that you already made in the designer.  But using the strategy pattern as proposed by ste5an would simplify this greatly.

-saige-
it_saigeDeveloperCommented:
Using the strategy pattern as proposed by ste5an, you could do something like:

Form1.vb -
Imports System.Runtime.CompilerServices
Imports EE_Q29144372

Public Class Form1
    Private Sub OnLoad(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim parents = New List(Of Object) From
        {
            New With {.Name = "nodBody", .Text = "Body", .Children = New List(Of Object) From
            {
                New With {.Name = "nodBodyComp", .Text = "Computed Body List", .IsActive = True, .Strategy = GetType(BodyComp)}
            }},
            New With {.Name = "nodMarker", .Text = "Marker", .Children = New List(Of Object) From
            {
                New With {.Name = "nodMarkerComp", .Text = "Computed Marker List", .IsActive = True, .Strategy = GetType(MarkerComp)}
            }},
            New With {.Name = "nodSubvar", .Text = "Subvar", .Children = New List(Of Object) From
            {
                New With {.Name = "nodSubvarPa", .Text = "Parameters", .IsActive = True, .Strategy = GetType(SubvarPa)},
                New With {.Name = "nodSubvarHp", .Text = "Kinematic Points", .IsActive = True, .Strategy = GetType(SubvarHp)},
                New With {.Name = "nodSubvarSens", .Text = "Sensor Points", .IsActive = False, .Strategy = GetType(SubvarSens)},
                New With {.Name = "nodSubvarMp", .Text = "Mass Properties", .IsActive = True, .Strategy = GetType(SubvarMp)},
                New With {.Name = "nodSubvarFe", .Text = "Force Elements", .IsActive = False, .Strategy = GetType(SubvarFe)},
                New With {.Name = "nodSubvar3d", .Text = "3D Visualization", .IsActive = False, .Strategy = GetType(Subvar3d)}
            }},
            New With {.Name = "nodForce", .Text = "Force", .Children = New List(Of Object) From
            {
                New With {.Name = "nodForce43", .Text = "43: Bushing Cmp", .IsActive = True, .Strategy = GetType(Force43)},
                New With {.Name = "nodForce18", .Text = "18: Unilateral Spring-Damper Cmp", .IsActive = True, .Strategy = GetType(Force18)},
                New With {.Name = "nodForce4", .Text = "4: Spring-Damper Parallel", .IsActive = True, .Strategy = GetType(Force4)}
            }},
            New With {.Name = "nodForceOut", .Text = "Force Output", .Children = New List(Of Object) From
            {
                New With {.Name = "nodForceOutDist", .Text = "Distance", .IsActive = True, .Strategy = GetType(ForceOutDist)},
                New With {.Name = "nodForceOut43", .Text = "43: Bushing Cmp", .IsActive = True, .Strategy = GetType(ForceOut43)},
                New With {.Name = "nodForceOut18", .Text = "18: Unilateral Spring-Damper Cmp", .IsActive = True, .Strategy = GetType(ForceOut18)},
                New With {.Name = "nodForceOut4", .Text = "4: Spring-Damper Parallel", .IsActive = True, .Strategy = GetType(ForceOut4)}
            }},
            New With {.Name = "nodIfctn", .Text = "Input Function", .Children = New List(Of Object) From
            {
                New With {.Name = "nodIfctnBase", .Text = "Input Functions", .IsActive = True, .Strategy = GetType(IfctnBase)}
            }},
            New With {.Name = "nodComm", .Text = "Communicator", .Children = New List(Of Object) From
            {
                New With {.Name = "nodCommSender", .Text = "Sender", .IsActive = True, .Strategy = GetType(CommSender)},
                New With {.Name = "nodCommReceiver", .Text = "Receiver", .IsActive = True, .Strategy = GetType(CommReceiver)}
            }},
            New With {.Name = "nodExpression", .Text = "Expression", .Children = New List(Of Object) From
            {
                New With {.Name = "nodExpressionCutForce", .Text = "Cut Force", .IsActive = True, .Strategy = GetType(ExpressionCutForce)}
            }},
            New With {.Name = "nodSolve", .Text = "Solve", .Children = New List(Of Object) From {
                New With {.Name = "nodSolvePreload", .Text = "Preload", .IsActive = True, .Strategy = GetType(SolvePreload)},
                New With {.Name = "nodSolveEqui", .Text = "Equilibrium", .IsActive = True, .Strategy = GetType(SolveEqui)},
                New With {.Name = "nodSolveEigen", .Text = "Eigen Value", .IsActive = True, .Strategy = GetType(SolveEigen)}
            }},
            New With {.Name = "nodNaming", .Text = "Naming", .Children = New List(Of Object) From {
                New With {.Name = "nodNamingSpck", .Text = "Spck", .IsActive = False, .Strategy = GetType(NamingSpck)},
                New With {.Name = "nodNamingCad", .Text = "Cad", .IsActive = False, .Strategy = GetType(NamingCad)},
                New With {.Name = "nodNamingFbi", .Text = "Fbi", .IsActive = False, .Strategy = GetType(NamingFbi)}
            }}
        }

        Dim node As TreeNode = Nothing
        Dim strategy As TreeNode = Nothing
        For Each p In parents
            node = New TreeNode(p.Text) With {.Name = p.Name}
            tView.Nodes.Add(node)
            For Each c In p.Children
                strategy = Activator.CreateInstance(c.Strategy)
                strategy.Text = c.Text
                strategy.Name = c.Name
                CType(strategy, IStrategy).IsActive = c.IsActive
                node.Nodes.Add(strategy)
            Next
        Next
    End Sub

    Private Sub OnClick(sender As Object, e As EventArgs) Handles Button1.Click
        FlowLayoutPanel1.Controls.Clear()
        Dim selected = GetChildNodes(tView.Nodes).Where(Function(n) n.Checked AndAlso TypeOf n Is IStrategy AndAlso n.Parent IsNot Nothing).Select(Function(n, i) New With {.Node = n, .Strategy = CType(n, IStrategy), .Index = i})
        For Each item In selected
            Try
                item.Strategy.Execute(Me, item.Node, item.Index)
            Catch ex As Exception
            End Try
        Next
    End Sub
End Class

Module Extensions
    <Extension>
    Public Iterator Function GetChildNodes(tree As TreeNodeCollection) As IEnumerable(Of TreeNode)
        For Each node In tree.OfType(Of TreeNode)
            Yield node
            For Each child In GetChildNodes(node.Nodes)
                Yield child
            Next
        Next
    End Function
End Module

Interface IStrategy
    Property IsActive() As Boolean
    Sub Execute(ByVal form As Form1, ByVal node As TreeNode, ByVal index As Integer)
End Interface

Public Class BodyComp
    Inherits TreeNode
    Implements IStrategy

    Public Property IsActive() As Boolean Implements IStrategy.IsActive

    Public Sub Execute(ByVal form As Form1, ByVal node As TreeNode, ByVal index As Integer) Implements IStrategy.Execute
        form.FlowLayoutPanel1.Controls.Add(New Button() With {.Text = $"{node.Text} - {index}", .BackColor = If(IsActive, Color.Green, Color.Orange), .ForeColor = If(IsActive, Color.White, Color.Black), .Width = form.FlowLayoutPanel1.Width - 10})
    End Sub
End Class

Public Class MarkerComp
    Inherits TreeNode
    Implements IStrategy

    Public Property IsActive() As Boolean Implements IStrategy.IsActive

    Public Sub Execute(ByVal form As Form1, ByVal node As TreeNode, ByVal index As Integer) Implements IStrategy.Execute
        form.FlowLayoutPanel1.Controls.Add(New Button() With {.Text = $"{node.Text} - {index}", .BackColor = If(IsActive, Color.Green, Color.Orange), .ForeColor = If(IsActive, Color.White, Color.Black), .Width = form.FlowLayoutPanel1.Width - 10})
    End Sub
End Class

Public Class SubvarPa
    Inherits TreeNode
    Implements IStrategy

    Public Property IsActive() As Boolean Implements IStrategy.IsActive

    Public Sub Execute(ByVal form As Form1, ByVal node As TreeNode, ByVal index As Integer) Implements IStrategy.Execute
        form.FlowLayoutPanel1.Controls.Add(New Button() With {.Text = $"{node.Text} - {index}", .BackColor = If(IsActive, Color.Green, Color.Orange), .ForeColor = If(IsActive, Color.White, Color.Black), .Width = form.FlowLayoutPanel1.Width - 10})
    End Sub
End Class

Public Class SubvarHp
    Inherits TreeNode
    Implements IStrategy

    Public Property IsActive() As Boolean Implements IStrategy.IsActive

    Public Sub Execute(ByVal form As Form1, ByVal node As TreeNode, ByVal index As Integer) Implements IStrategy.Execute
        form.FlowLayoutPanel1.Controls.Add(New Button() With {.Text = $"{node.Text} - {index}", .BackColor = If(IsActive, Color.Green, Color.Orange), .ForeColor = If(IsActive, Color.White, Color.Black), .Width = form.FlowLayoutPanel1.Width - 10})
    End Sub
End Class

Public Class SubvarSens
    Inherits TreeNode
    Implements IStrategy

    Public Property IsActive() As Boolean Implements IStrategy.IsActive

    Public Sub Execute(ByVal form As Form1, ByVal node As TreeNode, ByVal index As Integer) Implements IStrategy.Execute
        form.FlowLayoutPanel1.Controls.Add(New Button() With {.Text = $"{node.Text} - {index}", .BackColor = If(IsActive, Color.Green, Color.Orange), .ForeColor = If(IsActive, Color.White, Color.Black), .Width = form.FlowLayoutPanel1.Width - 10})
    End Sub
End Class

Public Class SubvarMp
    Inherits TreeNode
    Implements IStrategy

    Public Property IsActive() As Boolean Implements IStrategy.IsActive

    Public Sub Execute(ByVal form As Form1, ByVal node As TreeNode, ByVal index As Integer) Implements IStrategy.Execute
        form.FlowLayoutPanel1.Controls.Add(New Button() With {.Text = $"{node.Text} - {index}", .BackColor = If(IsActive, Color.Green, Color.Orange), .ForeColor = If(IsActive, Color.White, Color.Black), .Width = form.FlowLayoutPanel1.Width - 10})
    End Sub
End Class

Public Class SubvarFe
    Inherits TreeNode
    Implements IStrategy

    Public Property IsActive() As Boolean Implements IStrategy.IsActive

    Public Sub Execute(ByVal form As Form1, ByVal node As TreeNode, ByVal index As Integer) Implements IStrategy.Execute
        form.FlowLayoutPanel1.Controls.Add(New Button() With {.Text = $"{node.Text} - {index}", .BackColor = If(IsActive, Color.Green, Color.Orange), .ForeColor = If(IsActive, Color.White, Color.Black), .Width = form.FlowLayoutPanel1.Width - 10})
    End Sub
End Class

Public Class Subvar3d
    Inherits TreeNode
    Implements IStrategy

    Public Property IsActive() As Boolean Implements IStrategy.IsActive

    Public Sub Execute(ByVal form As Form1, ByVal node As TreeNode, ByVal index As Integer) Implements IStrategy.Execute
        form.FlowLayoutPanel1.Controls.Add(New Button() With {.Text = $"{node.Text} - {index}", .BackColor = If(IsActive, Color.Green, Color.Orange), .ForeColor = If(IsActive, Color.White, Color.Black), .Width = form.FlowLayoutPanel1.Width - 10})
    End Sub
End Class

Public Class Force43
    Inherits TreeNode
    Implements IStrategy

    Public Property IsActive() As Boolean Implements IStrategy.IsActive

    Public Sub Execute(ByVal form As Form1, ByVal node As TreeNode, ByVal index As Integer) Implements IStrategy.Execute
        form.FlowLayoutPanel1.Controls.Add(New Button() With {.Text = $"{node.Text} - {index}", .BackColor = If(IsActive, Color.Green, Color.Orange), .ForeColor = If(IsActive, Color.White, Color.Black), .Width = form.FlowLayoutPanel1.Width - 10})
    End Sub
End Class

Public Class Force18
    Inherits TreeNode
    Implements IStrategy

    Public Property IsActive() As Boolean Implements IStrategy.IsActive

    Public Sub Execute(ByVal form As Form1, ByVal node As TreeNode, ByVal index As Integer) Implements IStrategy.Execute
        form.FlowLayoutPanel1.Controls.Add(New Button() With {.Text = $"{node.Text} - {index}", .BackColor = If(IsActive, Color.Green, Color.Orange), .ForeColor = If(IsActive, Color.White, Color.Black), .Width = form.FlowLayoutPanel1.Width - 10})
    End Sub
End Class

Public Class Force4
    Inherits TreeNode
    Implements IStrategy

    Public Property IsActive() As Boolean Implements IStrategy.IsActive

    Public Sub Execute(ByVal form As Form1, ByVal node As TreeNode, ByVal index As Integer) Implements IStrategy.Execute
        form.FlowLayoutPanel1.Controls.Add(New Button() With {.Text = $"{node.Text} - {index}", .BackColor = If(IsActive, Color.Green, Color.Orange), .ForeColor = If(IsActive, Color.White, Color.Black), .Width = form.FlowLayoutPanel1.Width - 10})
    End Sub
End Class

Public Class ForceOutDist
    Inherits TreeNode
    Implements IStrategy

    Public Property IsActive() As Boolean Implements IStrategy.IsActive

    Public Sub Execute(ByVal form As Form1, ByVal node As TreeNode, ByVal index As Integer) Implements IStrategy.Execute
        form.FlowLayoutPanel1.Controls.Add(New Button() With {.Text = $"{node.Text} - {index}", .BackColor = If(IsActive, Color.Green, Color.Orange), .ForeColor = If(IsActive, Color.White, Color.Black), .Width = form.FlowLayoutPanel1.Width - 10})
    End Sub
End Class

Public Class ForceOut43
    Inherits TreeNode
    Implements IStrategy

    Public Property IsActive() As Boolean Implements IStrategy.IsActive

    Public Sub Execute(ByVal form As Form1, ByVal node As TreeNode, ByVal index As Integer) Implements IStrategy.Execute
        form.FlowLayoutPanel1.Controls.Add(New Button() With {.Text = $"{node.Text} - {index}", .BackColor = If(IsActive, Color.Green, Color.Orange), .ForeColor = If(IsActive, Color.White, Color.Black), .Width = form.FlowLayoutPanel1.Width - 10})
    End Sub
End Class

Public Class ForceOut18
    Inherits TreeNode
    Implements IStrategy

    Public Property IsActive() As Boolean Implements IStrategy.IsActive

    Public Sub Execute(ByVal form As Form1, ByVal node As TreeNode, ByVal index As Integer) Implements IStrategy.Execute
        form.FlowLayoutPanel1.Controls.Add(New Button() With {.Text = $"{node.Text} - {index}", .BackColor = If(IsActive, Color.Green, Color.Orange), .ForeColor = If(IsActive, Color.White, Color.Black), .Width = form.FlowLayoutPanel1.Width - 10})
    End Sub
End Class

Public Class ForceOut4
    Inherits TreeNode
    Implements IStrategy

    Public Property IsActive() As Boolean Implements IStrategy.IsActive

    Public Sub Execute(ByVal form As Form1, ByVal node As TreeNode, ByVal index As Integer) Implements IStrategy.Execute
        form.FlowLayoutPanel1.Controls.Add(New Button() With {.Text = $"{node.Text} - {index}", .BackColor = If(IsActive, Color.Green, Color.Orange), .ForeColor = If(IsActive, Color.White, Color.Black), .Width = form.FlowLayoutPanel1.Width - 10})
    End Sub
End Class

Public Class IfctnBase
    Inherits TreeNode
    Implements IStrategy

    Public Property IsActive() As Boolean Implements IStrategy.IsActive

    Public Sub Execute(ByVal form As Form1, ByVal node As TreeNode, ByVal index As Integer) Implements IStrategy.Execute
        form.FlowLayoutPanel1.Controls.Add(New Button() With {.Text = $"{node.Text} - {index}", .BackColor = If(IsActive, Color.Green, Color.Orange), .ForeColor = If(IsActive, Color.White, Color.Black), .Width = form.FlowLayoutPanel1.Width - 10})
    End Sub
End Class

Public Class CommSender
    Inherits TreeNode
    Implements IStrategy

    Public Property IsActive() As Boolean Implements IStrategy.IsActive

    Public Sub Execute(ByVal form As Form1, ByVal node As TreeNode, ByVal index As Integer) Implements IStrategy.Execute
        form.FlowLayoutPanel1.Controls.Add(New Button() With {.Text = $"{node.Text} - {index}", .BackColor = If(IsActive, Color.Green, Color.Orange), .ForeColor = If(IsActive, Color.White, Color.Black), .Width = form.FlowLayoutPanel1.Width - 10})
    End Sub
End Class

Public Class CommReceiver
    Inherits TreeNode
    Implements IStrategy

    Public Property IsActive() As Boolean Implements IStrategy.IsActive

    Public Sub Execute(ByVal form As Form1, ByVal node As TreeNode, ByVal index As Integer) Implements IStrategy.Execute
        form.FlowLayoutPanel1.Controls.Add(New Button() With {.Text = $"{node.Text} - {index}", .BackColor = If(IsActive, Color.Green, Color.Orange), .ForeColor = If(IsActive, Color.White, Color.Black), .Width = form.FlowLayoutPanel1.Width - 10})
    End Sub
End Class

Public Class ExpressionCutForce
    Inherits TreeNode
    Implements IStrategy

    Public Property IsActive() As Boolean Implements IStrategy.IsActive

    Public Sub Execute(ByVal form As Form1, ByVal node As TreeNode, ByVal index As Integer) Implements IStrategy.Execute
        form.FlowLayoutPanel1.Controls.Add(New Button() With {.Text = $"{node.Text} - {index}", .BackColor = If(IsActive, Color.Green, Color.Orange), .ForeColor = If(IsActive, Color.White, Color.Black), .Width = form.FlowLayoutPanel1.Width - 10})
    End Sub
End Class

Public Class SolvePreload
    Inherits TreeNode
    Implements IStrategy

    Public Property IsActive() As Boolean Implements IStrategy.IsActive

    Public Sub Execute(ByVal form As Form1, ByVal node As TreeNode, ByVal index As Integer) Implements IStrategy.Execute
        form.FlowLayoutPanel1.Controls.Add(New Button() With {.Text = $"{node.Text} - {index}", .BackColor = If(IsActive, Color.Green, Color.Orange), .ForeColor = If(IsActive, Color.White, Color.Black), .Width = form.FlowLayoutPanel1.Width - 10})
    End Sub
End Class

Public Class SolveEqui
    Inherits TreeNode
    Implements IStrategy

    Public Property IsActive() As Boolean Implements IStrategy.IsActive

    Public Sub Execute(ByVal form As Form1, ByVal node As TreeNode, ByVal index As Integer) Implements IStrategy.Execute
        form.FlowLayoutPanel1.Controls.Add(New Button() With {.Text = $"{node.Text} - {index}", .BackColor = If(IsActive, Color.Green, Color.Orange), .ForeColor = If(IsActive, Color.White, Color.Black), .Width = form.FlowLayoutPanel1.Width - 10})
    End Sub
End Class

Public Class SolveEigen
    Inherits TreeNode
    Implements IStrategy

    Public Property IsActive() As Boolean Implements IStrategy.IsActive

    Public Sub Execute(ByVal form As Form1, ByVal node As TreeNode, ByVal index As Integer) Implements IStrategy.Execute
        form.FlowLayoutPanel1.Controls.Add(New Button() With {.Text = $"{node.Text} - {index}", .BackColor = If(IsActive, Color.Green, Color.Orange), .ForeColor = If(IsActive, Color.White, Color.Black), .Width = form.FlowLayoutPanel1.Width - 10})
    End Sub
End Class

Public Class NamingSpck
    Inherits TreeNode
    Implements IStrategy

    Public Property IsActive() As Boolean Implements IStrategy.IsActive

    Public Sub Execute(ByVal form As Form1, ByVal node As TreeNode, ByVal index As Integer) Implements IStrategy.Execute
        form.FlowLayoutPanel1.Controls.Add(New Button() With {.Text = $"{node.Text} - {index}", .BackColor = If(IsActive, Color.Green, Color.Orange), .ForeColor = If(IsActive, Color.White, Color.Black), .Width = form.FlowLayoutPanel1.Width - 10})
    End Sub
End Class

Public Class NamingCad
    Inherits TreeNode
    Implements IStrategy

    Public Property IsActive() As Boolean Implements IStrategy.IsActive

    Public Sub Execute(ByVal form As Form1, ByVal node As TreeNode, ByVal index As Integer) Implements IStrategy.Execute
        form.FlowLayoutPanel1.Controls.Add(New Button() With {.Text = $"{node.Text} - {index}", .BackColor = If(IsActive, Color.Green, Color.Orange), .ForeColor = If(IsActive, Color.White, Color.Black), .Width = form.FlowLayoutPanel1.Width - 10})
    End Sub
End Class

Public Class NamingFbi
    Inherits TreeNode
    Implements IStrategy

    Public Property IsActive() As Boolean Implements IStrategy.IsActive

    Public Sub Execute(ByVal form As Form1, ByVal node As TreeNode, ByVal index As Integer) Implements IStrategy.Execute
        form.FlowLayoutPanel1.Controls.Add(New Button() With {.Text = $"{node.Text} - {index}", .BackColor = If(IsActive, Color.Green, Color.Orange), .ForeColor = If(IsActive, Color.White, Color.Black), .Width = form.FlowLayoutPanel1.Width - 10})
    End Sub
End Class

Open in new window

Form1.Designer.vb -
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
    Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.SplitContainer1 = New System.Windows.Forms.SplitContainer()
        Me.tView = New System.Windows.Forms.TreeView()
        Me.SplitContainer2 = New System.Windows.Forms.SplitContainer()
        Me.Button1 = New System.Windows.Forms.Button()
        Me.FlowLayoutPanel1 = New System.Windows.Forms.FlowLayoutPanel()
        CType(Me.SplitContainer1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SplitContainer1.Panel1.SuspendLayout()
        Me.SplitContainer1.Panel2.SuspendLayout()
        Me.SplitContainer1.SuspendLayout()
        CType(Me.SplitContainer2, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SplitContainer2.Panel1.SuspendLayout()
        Me.SplitContainer2.Panel2.SuspendLayout()
        Me.SplitContainer2.SuspendLayout()
        Me.SuspendLayout()
        '
        'SplitContainer1
        '
        Me.SplitContainer1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.SplitContainer1.Location = New System.Drawing.Point(0, 0)
        Me.SplitContainer1.Name = "SplitContainer1"
        '
        'SplitContainer1.Panel1
        '
        Me.SplitContainer1.Panel1.Controls.Add(Me.tView)
        '
        'SplitContainer1.Panel2
        '
        Me.SplitContainer1.Panel2.Controls.Add(Me.FlowLayoutPanel1)
        Me.SplitContainer1.Size = New System.Drawing.Size(800, 399)
        Me.SplitContainer1.SplitterDistance = 266
        Me.SplitContainer1.TabIndex = 0
        '
        'tView
        '
        Me.tView.CheckBoxes = True
        Me.tView.Dock = System.Windows.Forms.DockStyle.Fill
        Me.tView.Location = New System.Drawing.Point(0, 0)
        Me.tView.Name = "tView"
        Me.tView.Size = New System.Drawing.Size(266, 399)
        Me.tView.TabIndex = 1
        '
        'SplitContainer2
        '
        Me.SplitContainer2.Dock = System.Windows.Forms.DockStyle.Fill
        Me.SplitContainer2.Location = New System.Drawing.Point(0, 0)
        Me.SplitContainer2.Name = "SplitContainer2"
        Me.SplitContainer2.Orientation = System.Windows.Forms.Orientation.Horizontal
        '
        'SplitContainer2.Panel1
        '
        Me.SplitContainer2.Panel1.Controls.Add(Me.Button1)
        '
        'SplitContainer2.Panel2
        '
        Me.SplitContainer2.Panel2.Controls.Add(Me.SplitContainer1)
        Me.SplitContainer2.Size = New System.Drawing.Size(800, 450)
        Me.SplitContainer2.SplitterDistance = 47
        Me.SplitContainer2.TabIndex = 1
        '
        'Button1
        '
        Me.Button1.Dock = System.Windows.Forms.DockStyle.Left
        Me.Button1.Location = New System.Drawing.Point(0, 0)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(75, 47)
        Me.Button1.TabIndex = 0
        Me.Button1.Text = "Run"
        Me.Button1.UseVisualStyleBackColor = True
        '
        'FlowLayoutPanel1
        '
        Me.FlowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.FlowLayoutPanel1.Location = New System.Drawing.Point(0, 0)
        Me.FlowLayoutPanel1.Name = "FlowLayoutPanel1"
        Me.FlowLayoutPanel1.Size = New System.Drawing.Size(530, 399)
        Me.FlowLayoutPanel1.TabIndex = 0
        '
        'Form1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(8.0!, 16.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(800, 450)
        Me.Controls.Add(Me.SplitContainer2)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.SplitContainer1.Panel1.ResumeLayout(False)
        Me.SplitContainer1.Panel2.ResumeLayout(False)
        CType(Me.SplitContainer1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.SplitContainer1.ResumeLayout(False)
        Me.SplitContainer2.Panel1.ResumeLayout(False)
        Me.SplitContainer2.Panel2.ResumeLayout(False)
        CType(Me.SplitContainer2, System.ComponentModel.ISupportInitialize).EndInit()
        Me.SplitContainer2.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

    Friend WithEvents SplitContainer1 As SplitContainer
    Friend WithEvents tView As TreeView
    Friend WithEvents SplitContainer2 As SplitContainer
    Friend WithEvents Button1 As Button
    Friend WithEvents FlowLayoutPanel1 As FlowLayoutPanel
End Class

Open in new window

Which produces the following output -Capture.PNGUnderstand that this is purely for demonstrative purposes only.  Since all of the Strategies perform the same function, I could conceivably define only one strategy.

-saige-

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HakanAuthor Commented:
thanks for your helps and contributions. i'm really appreciate for your helps.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.