Nevron Forum

Context Menu and NTreeList

https://www.nevron.com/Forum/Topic4131.aspx

By Vince McMullin 1 - Tuesday, September 7, 2010

I would like to display a different context menu for each node collection on a NTreeList but I am having trouble figuring out how to do that exactly.

How do I check to see what the NTreeListNodeStringSubItem is equal to and then based on that display the proper context menu for the node collection?

Right now I have something that looks like this but it doesn't work:

Public Sub Quality_Click(ByVal sender As System.Object, ByVal e As MouseEventArgs) Handles NTreeList0.MouseClick

Dim pt As NPoint = New NPoint(e.Location)

Dim node As NTreeListNode = NTreeList0.ItemFromPoint(pt, True)


For i As Integer = 0 To node.SubItems.Count - 1


Dim r As Rectangle = node.SubItems(i).ViewBounds.ToRectangle()

If r.Contains(e.Location) Then


MessageBox.Show(node.SubItems(i).ToString)


Return

End If
Next


End Sub
By Nevron Support - Tuesday, September 7, 2010

Hello Vince,

You can try the following:

Private Sub NTreeList1_Click(ByVal sender As Object, ByVal e As MouseEventArgs) Handles NTreeList1.MouseClick
    Dim p As NPoint = New NPoint(e.Location)
    If e.Button = Windows.Forms.MouseButtons.Right Then
        Dim node As NTreeListNode = NTreeList1.ItemFromPoint(p)
        If node Is Nothing Then
            Return
        End If
        Dim clickedItem As NTreeListNodeSubItem = node.ResolveSubItem(ColumnFromPoint(p))
        If clickedItem Is Nothing Then
            Return
        End If
        Dim contextMenu As NContextMenu = New NContextMenu()
        ...
        contextMenu.Show(clickedItem, MousePosition)
    End If
End Sub

Private Function ColumnFromPoint(ByVal p As NPoint) As NTreeListColumn
    For i As Integer = 0 To NTreeList1.Columns.Count - 1
        Dim current As NTreeListColumn = NTreeList1.Columns(i)
        If current.ViewBounds.Contains(p) Then
            Return current
        End If
    Next
    Return Nothing
End Function