Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Treeview + CheckBox + ContextMenu
Message
De
14/02/2004 16:45:09
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00877414
Message ID:
00877426
Vues:
20
This message has been marked as the solution to the initial question of the thread.
Eric,

You shouldn't need to do anything special other than test for the "Edit" mode in the oContextMenu_Popup eventhandler (and then don't create the popup menu items). Are you doing this and it's not working?

~~Bonnie


>Hi Bonnie
>
>Thanks for your answer. It is almost working all correctly now!
>
>The only thing is that I don't want the context menu to be displayed if it is not in "Edit" mode. In my previous, I had a check on that.
>I have replaced my complete MouseUp event handler with the setting of the treeview's ContextMenu property and with this event to be sure that the correct node is selected:
>
>
Private Sub tvwSecurite_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles tvwSecurite.MouseDown
>    If e.Button = MouseButtons.Right Then
>        tvwSecurite.SelectedNode = tvwSecurite.GetNodeAt(e.X, e.Y)
>    End If
>End Sub
>
>
>
>Where can I cancel the click now if the user is not in edit mode?
>
>
>
>>Eric,
>>
>>You don't really have to mess with clicks and other mouse events to display and capture ContextMenus. I think that is what's causing you problems (although I haven't used a TreeView with checkboxes in it, but I doubt that this is the problem). I'm sorry to have to post this in C# rather than VB, but I tried to use the C#-to-VB converters and they didn't particularly like the way C# does delegates and event handlers. I hope you can figure it out:
>>
>>
>>// Set the Tree's ContextMenu
>>this.oTree.ContextMenu = this.oContextMenu
>>
>>// Set the ContextMenu Popup event handler
>>this.oContextMenu.Popup += new System.EventHandler(this.oContextMenu_Popup);
>>
>>private void oContextMenu_Popup(object sender, System.EventArgs e)
>>{
>>  this.oContextMenu.MenuItems.Clear();
>>  MenuItem oItem;
>>
>>  // Create all the appropriate ContextMenu items. This can vary
>>  // depending on which node in the TreeView was clicked. I have a Node class
>>  // defined in the control that adds additional functionality to the TreeNode class,
>>  // so I can tell which type of Node has been selected
>>  MyTreeNode node = (MyTreeNode)this.oTree.SelectedNode;
>>  if (node.IsTypeOne)
>>  {
>>    // Create one type of context menu
>>    oItem = new MenuItem("Text For Type One");
>>    oItem.Click += new System.EventHandler(this.oMenu_Handler);
>>    this.oContextMenu.MenuItems.Add(oItem);
>>  }
>>  else if (node.IsTypeTwo)
>>  {
>>    // Create another type of context menu
>>    oItem = new MenuItem("Text For Type Two");
>>    oItem.Click += new System.EventHandler(this.oMenu_Handler);
>>    this.oContextMenu.MenuItems.Add(oItem);
>>  }
>>}
>>
>>private void oMenu_Handler(object sender, System.EventArgs e)
>>{
>>  MenuItem oItem = (MenuItem)sender;
>>
>>  // Process whichever ContextMenu item was selected
>>  if (item.Text == "Text For Type One")
>>    // code to process type one
>>  else if (item.Text == "Text For Type Two")
>>    // code to process type two
>>}
>>
>>
>>~~Bonnie
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform