private void SessionExecutionTreeView_ContextMenuOpening(object sender, TreeViewContextMenuOpeningEventArgs e) { if (e.Node == null || e.Node.Tag == null) { e.Cancel = true; return; } SessionMapElement element = e.Node.Tag as SessionMapElement; switch (element.ElementType) { // Virtual hosts can show the menu if they are starting up case ElementType.Machine: e.Cancel = (element.State != RuntimeState.Starting); break; // Simulators can show the menu if they are starting up case ElementType.Device: if (element.ElementSubtype == "JediSimulator") { e.Cancel = (element.State != RuntimeState.Starting); } else { // Only display if it's Running or Offline e.Cancel = (element.State != RuntimeState.Running && element.State != RuntimeState.Offline); } break; // Worker type virtual resources can show the menu if they are running or paused case ElementType.Worker: List <string> workerResourceTypes = new List <string>() { "OfficeWorker", "AdminWorker", "CitrixWorker" }; if (workerResourceTypes.Contains(element.ElementSubtype)) { e.Cancel = (element.State != RuntimeState.Running && element.State != RuntimeState.Paused); } else { e.Cancel = true; } break; // No menus for anything else default: e.Cancel = true; break; } // If we are going to allow the menu to be shown, configure it and save the selected element for later if (!e.Cancel) { ConfigureContextMenu(element); _contextMenuElement = element; } }
private void radTreeView1_ContextMenuOpening(object sender, TreeViewContextMenuOpeningEventArgs e) { for (int i = e.Menu.Items.Count - 1; i >= 0; i--) { if (e.Menu.Items[i].Name == "Delete") { this.removeButton_Click(null,null); } if (e.Menu.Items[i].Name == "New") { this.addButton_Click(null, null); } } }