/// <summary> /// This is the handler for when we change an item on the context menu /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void contextMenuItem_Click(object sender, EventArgs e) { // Uncheck any currently checked menu item foreach (IGMenuItem thisMenuItem in contextMenu1.MenuItems) { if (thisMenuItem.Checked) { thisMenuItem.Checked = false; } } IGMenuItem menuItem = sender as IGMenuItem; if (menuItem != null) { if (menuItem.Tag is UltraListViewStyle) { menuItem.Checked = true; UltraListViewStyle view = (UltraListViewStyle)menuItem.Tag; this.assetListView.View = view; Properties.Settings.Default.ViewStyle = view; Properties.Settings.Default.Save(); RefreshView(); } } }
public ComputerTabView([ServiceDependency] WorkItem workItem) { this.workItem = workItem as LaytonWorkItem; InitializeComponent(); // Set the List View style assetListView.ShowGroups = true; assetListView.View = Properties.Settings.Default.ViewStyle; // Setup the context menu used by the list view assetListView.ContextMenu = this.contextMenu1; // Populate the context menu with the constants of the UltraListViewStyle // enumeration, so we can allow the end user to change the view. Note that we // will not support the 'Details' view as this is not really appropriate IGMenuItem menuItem = null; string[] enumNames = Enum.GetNames(typeof(UltraListViewStyle)); Array enumValues = Enum.GetValues(typeof(UltraListViewStyle)); for (int i = 0; i < enumValues.Length; i++) { // Skip details mode if (enumNames[i] == UltraListViewStyle.Details.ToString()) { continue; } menuItem = new IGMenuItem(enumNames[i], new EventHandler(this.contextMenuItem_Click)); UltraListViewStyle enumValue = (UltraListViewStyle)enumValues.GetValue(i); menuItem.Tag = enumValue; // If this value is the same one that the control's View // property is set to, check it if (assetListView.View == enumValue) { menuItem.Checked = true; } this.contextMenu1.MenuItems.Add(menuItem); } }