Thanks Gav, it seems to work in my win app.
I'm writing the same thing for the compact framework too but I'm stuck
there since there's no GetNodeAt Function but more important there's no
MouseDown event when I 'Tap and Hold'.
Kind regards,
Mike
Hi Mike,
For compact framework to enable/disble the context menu for a tree view
following this step:
1. Add a context menu to form, drag and drop the context menu from the tool
box to the form.
2. Add a handler for AfterSelect event, for example:
this.treeView.AfterSelect += new
System.Windows.Forms.TreeViewEventHandler(this.treeView_AfterSelect);
3. Inside the callback set the context menu based on your logic, for example:
private void treeView_AfterSelect(object sender,
System.Windows.Forms.TreeViewEventArgs e)
{
if ( e.Node.Text.Equals("Documents & Settings") )
{
this.treeView.ContextMenu = this.contextMenu;
}
else
{
this.treeView.ContextMenu = null;
}
}
In this example the only the node has text equals to "Documents & Settings"
will have a context menu, other one will not.
Hope this help,
Dinhduy Tran
[CSDP/MCSD]
> Thanks Gav, it seems to work in my win app.
> I'm writing the same thing for the compact framework too but I'm stuck
[quoted text clipped - 3 lines]
> Kind regards,
> Mike
Nickneem - 18 Aug 2005 20:57 GMT
Thanks Dinhduy, works like a charm!
To make things complete, here's most of the code:
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
AddHandler treeMenu.AfterSelect, New
System.windows.forms.TreeViewEventHandler(AddressOf
treeView_AfterSelect)
End Sub
#Region "ContextMenu"
Private Sub mnuMemo_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles mnuMemo.Click
'Right Click / Tap and hold = memo meegeven
Dim rClickedNode As New InheritTreeNode
Dim MemoString As String
Try
rClickedNode = CType(treeMenu.SelectedNode,
InheritTreeNode)
If rClickedNode.ItemNode = True Then
InputPanel1.Enabled = True
MemoString = InputBox("Memo?", "DigiWaiter PDA")
If MemoString <> "" Then 'Alleen als er wat ingegeven
is
rClickedNode.notitie = MemoString
End If
InputPanel1.Enabled = False
End If
Catch ex As Exception
End Try
End Sub
Private Sub treeView_AfterSelect(ByVal sender As Object, ByVal e As
System.Windows.Forms.TreeViewEventArgs)
Dim rClickedNode As New InheritTreeNode
Try
rClickedNode = CType(e.Node, InheritTreeNode)
If rClickedNode.ItemNode.Equals(True) Then
Me.treeMenu.ContextMenu = Me.ContextMenu1
Else
Me.treeMenu.ContextMenu = Nothing
End If
Catch ex As Exception
End Try
End Sub
#Region "ContextMenu"
Public Class InheritTreeNode
Inherits TreeNode
' The Name property uniquely identifies the user connection.
Private _notitie As String
Private _ItemNode As Boolean
Public Property notitie() As String
Get
Return _notitie
End Get
Set(ByVal Value As String)
_notitie = Value
End Set
End Property
Public Property ItemNode() As Boolean
Get
Return _ItemNode
End Get
Set(ByVal Value As Boolean)
_ItemNode = Value
End Set
End Property
End Class
Thanks for your help guys!
Regards,
Michael