private void grid_ItemClicked(MyGuiControlGrid sender, MyGuiControlGrid.EventArgs eventArgs) { if (eventArgs.Button == MySharedButtonsEnum.Secondary) { int slot = eventArgs.ColumnIndex; var toolbar = MyToolbarComponent.CurrentToolbar; MyToolbarItem item = toolbar.GetSlotItem(slot); if (item == null) { return; } //right clicks in multifunctional items should trigger their menus (if they have more than 0 options) if (item is MyToolbarItemActions) { var actionList = (item as MyToolbarItemActions).PossibleActions(ShownToolbar.ToolbarType); if (UseContextMenu && actionList.Count > 0) { m_contextMenu.CreateNewContextMenu(); foreach (var action in actionList) { m_contextMenu.AddItem(action.Name, icon: action.Icon, userData: action.Id); } m_contextMenu.AddItem(MyTexts.Get(MySpaceTexts.BlockAction_RemoveFromToolbar)); m_contextMenu.Enabled = true; m_contextMenuItemIndex = toolbar.SlotToIndex(slot); } else { RemoveToolbarItem(eventArgs.ColumnIndex); } } else { RemoveToolbarItem(eventArgs.ColumnIndex); } } if (m_shownToolbar.IsValidIndex(eventArgs.ColumnIndex)) { m_shownToolbar.ActivateItemAtSlot(eventArgs.ColumnIndex, true); } }