简体   繁体   English

从动态树视图中选择节点

[英]select node from dynamic treeview

I am creating some treeviews at runtime and need to get value of the nodes that have been selected in one of these treeviews.我正在运行时创建一些树视图,需要获取在这些树视图之一中选择的节点的值。 How can I accomplish this.我怎样才能做到这一点。 A google search did not return any useful answers.谷歌搜索没有返回任何有用的答案。

 Private Sub line_balancing_context_Opening(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles line_balancing_context.Opening
    Dim wksnum1 As Integer = 0
    Dim wksact As Integer = 0
    Dim wkstations1() As String = Nothing
    Dim wksactivity() As String = Nothing
    Dim currentsheet As String
    Dim stationtree1 As TreeView
    Dim actname As TreeNode = Nothing
    Dim item As ContextMenuStrip
    Dim subitem() As ToolStripDropDownButton
    For Each Control In display_splitcontainer.Panel1.Controls
        If TypeOf Control Is TreeView Then
            If MouseIsOverControl(Control) = True Then
                stationtree1 = New TreeView
                stationtree1 = Control
                startsheet = stationtree1.Name
            End If
        End If
    Next
    line_balancing_context.Items.Clear()
    osheet = obooks.ActiveSheet
    currentsheet = osheet.Name
    osheet = obooks.Worksheets("Relations Form")
    orng = osheet.Range("A1")
    Do Until orng.Value Is Nothing
        orng = orng.Offset(, 1)
        wksnum1 = wksnum1 + 1
        ReDim Preserve wkstations1(0 To wksnum1)
        wkstations1(wksnum1 - 1) = orng.Value
    Loop
    For Me.i = 0 To wkstations1.Length - 1
        If Not wkstations1(i) Is Nothing Then
            line_balancing_context.Items.Add(wkstations1(i))
        End If
    Next

    osheet = obooks.Worksheets(currentsheet)
    osheet.Activate()
End Sub
Private Sub linebalancingcontext_ItemClicked(ByVal sender As Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles line_balancing_context.ItemClicked
    sheetname = e.ClickedItem.Text
    Dim stationtree1 As TreeView
    Dim actname As TreeNode = Nothing
    Dim stationtree2 As TreeView
    For Each Control In display_splitcontainer.Panel1.Controls
        If TypeOf Control Is TreeView Then
            stationtree1 = New TreeView
            stationtree1 = Control
            If stationtree1.Name = startsheet Then
                If Not stationtree1.SelectedNode Is Nothing Then
                    actname = stationtree1.SelectedNode
                    actname.Remove()
                    Exit For
                End If
            End If
        End If
    Next

    For Each Control In display_splitcontainer.Panel1.Controls
        If TypeOf Control Is TreeView Then
            stationtree2 = New TreeView
            stationtree2 = Control
            If stationtree2.Name = sheetname Then
                If stationtree2.Nodes.ContainsKey(actname.Text) Then
                    actname.Remove()
                End If
                stationtree2.Nodes.Add(actname)
                Exit For
            End If
        End If
    Next
    If MTM_analyser.worksheetexists(startsheet & "M") Then

        osheet = obooks.Worksheets(startsheet & "M")
        osheet.Activate()
        With osheet.UsedRange
            orng = .Find("Description of Action")
            col1 = orng.Column
            orng = .Find("Parent Activity")
            col2 = orng.Column
        End With
        orng = osheet.Range(Chr(64 + col1) & ":" & Chr(64 + col1)).Find(actname.Text)
        If Not orng Is Nothing Then
            parent1 = CType(osheet.Cells(orng.Row, col2), excel.Range).Value
            Dim some As String = "A" & orng.Row & ":" & "XFD" & orng.Row
            osheet.Range(some).Cut()
            object1 = osheet.Range(some)
            osheet2 = obooks.Worksheets(sheetname & "M")
            osheet2.Activate()
            row1 = lastrowmtm(sheetname & "M")
            If parent1 = startsheet Then

                Dim some1 As String = "A" & row1 & ":" & "XFD" & row1
                If Not object1 Is Nothing Then
                    osheet2.Range(some1).Insert(, object1)
                End If
                CType(osheet.Cells(row1, col2), excel.Range).Value = sheetname
                object1 = Nothing
            End If
        End If
    End If
    transferactivity(actname)
End Sub
Sub transferactivity(ByVal aTreeNode As TreeNode)
    Dim n As TreeNode
    sheetnum = 0
    For Each n In aTreeNode.Nodes
        transferRecursive(n)
    Next
End Sub
Private Sub transferRecursive(ByVal n As TreeNode)
    System.Diagnostics.Debug.WriteLine(n.Text)
    If MTM_analyser.worksheetexists(startsheet & "M") Then
        osheet = obooks.Worksheets(startsheet & "M")
        osheet.Activate()
        With osheet.UsedRange
            orng = .Find("Description of Action")
            col1 = orng.Column
            orng = .Find("Parent Activity")
            col2 = orng.Column
        End With
        orng = osheet.Range(Chr(64 + col1) & ":" & Chr(64 + col1)).Find(n.Text)
        If Not orng Is Nothing Then
            parent1 = CType(osheet.Cells(orng.Row, col2), excel.Range).Value
            Dim some As String = "A" & orng.Row & ":" & "XFD" & orng.Row
            osheet.Range(some).Cut()
            object1 = osheet.Range(some)
            osheet2 = obooks.Worksheets(sheetname & "M")
            osheet2.Activate()
            If parent1 = startsheet Then
                MsgBox("woaah")
            Else
                orng2 = osheet2.Range(Chr(64 + col1) & ":" & Chr(64 + col1)).Find(parent1)
                osheet2.Range("A" & orng2.Row + 1 & ":" & "XFD" & orng2.Row + 1).Insert(, object1)
                osheet.Range(some).EntireRow.Delete()
            End If
        End If
    End If
    Dim aNode As TreeNode
    For Each aNode In n.Nodes
        transferactivity(aNode)
    Next
End Sub

I am using a context menu to popup t allow me to shift node along with the data attached to it to another location.我正在使用上下文菜单弹出 t 允许我将节点以及附加到它的数据移动到另一个位置。 the data handling is being done in excel so i needed to get all the information of the node.数据处理是在excel中完成的,所以我需要获取节点的所有信息。

the problem that i face now is that i am not able to directly right click on a node to get the context strip if done the first node gets selected and not the one that was clicked how can i resolve this issue.我现在面临的问题是,如果完成第一个节点而不是被单击的节点,我无法直接右键单击节点以获取上下文条,我该如何解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM