/// <devdoc> /// Adds the collection of items to the list view. /// This collection should contain AssemblyEntry objects. /// </devdoc> public void AddItems(ICollection items) { Hashtable duplicateHash = new Hashtable(items.Count); foreach (AssemblyEntry entry in items) { foreach (ToolboxItem item in entry.Items) { if (!duplicateHash.ContainsKey(item)) { ToolboxListViewItem tbi = new ToolboxListViewItem(item); controlList.Items.Add(tbi); duplicateHash[item] = item; } } } controlList.ListViewItemSorter = new ListSorter(-1, SortOrder.Ascending); }
/// <devdoc> /// Updates the initial checks on all the items. Any items found inside the /// toolbox will be checked. /// </devdoc> public void CheckItems(IToolboxService toolboxSvc) { ToolboxItemCollection items = toolboxSvc.GetToolboxItems(); // If the toolbox contains items not listed in the SDK, add // them to this list. After our check scan we will walk // the list and add any new items to the listview. // Hashtable additionalItems = null; // But...we can't match toolbox items to list view items // without an expensive n^2 search. Hash the list view // items by their underlying ToolboxItem object. // Hashtable itemHash = new Hashtable(controlList.Items.Count); foreach (ToolboxListViewItem item in controlList.Items) { itemHash[item.Item] = item; } // Now walk the toolbox items. // foreach (ToolboxItem item in items) { ToolboxListViewItem lvItem = (ToolboxListViewItem)itemHash[item]; if (lvItem != null) { lvItem.InitiallyChecked = true; lvItem.Checked = true; } else { // Verify that this item has an assembly name before // adding it. If it doesn't, then we don't have enough // data to add it. // if (item.AssemblyName != null && item.AssemblyName.Name != null) { if (additionalItems == null) { additionalItems = new Hashtable(); } additionalItems[item] = item; } } } // Finally, if we got additional items, add them in. // if (additionalItems != null) { IComparer sorter = controlList.ListViewItemSorter; controlList.ListViewItemSorter = null; try { foreach (ToolboxItem item in additionalItems.Keys) { ToolboxListViewItem lvItem = new ToolboxListViewItem(item); lvItem.InitiallyChecked = true; lvItem.Checked = true; controlList.Items.Add(lvItem); } } finally { controlList.ListViewItemSorter = sorter; } } }
/// <devdoc> /// Adds all the toolbox items found in the given file. This will display an error if the /// file does not contain an assembly. /// </devdoc> private void AddItems(string fileName) { if (File.Exists(fileName)) { Exception displayException = null; try { Cursor oldCursor = Cursor.Current; Cursor.Current = Cursors.WaitCursor; ToolboxListViewItem firstItem = null; IComparer comparer = controlList.ListViewItemSorter; controlList.ListViewItemSorter = null; controlList.SelectedItems.Clear(); try { ToolboxService.ToolboxElement[] elements = ToolboxService.EnumerateToolboxElements(fileName, null); foreach (ToolboxService.ToolboxElement element in elements) { ToolboxListViewItem existingItem = null; foreach (ToolboxListViewItem i in controlList.Items) { if (i.Item.Equals(element.Item)) { existingItem = i; break; } } if (existingItem == null) { ToolboxListViewItem item = new ToolboxListViewItem(element.Item); item.Checked = true; controlList.Items.Add(item); existingItem = item; } if (firstItem == null) { firstItem = existingItem; } existingItem.Selected = true; } } finally { controlList.ListViewItemSorter = comparer; Cursor.Current = oldCursor; } if (firstItem != null) { int index = controlList.Items.IndexOf(firstItem); if (index != -1) { controlList.EnsureVisible(index); } } else { displayException = new Exception(SR.GetString(SR.AddRemoveComponentsNoComponents, fileName)); } } catch (BadImageFormatException) { displayException = new Exception(SR.GetString(SR.AddRemoveComponentsBadModule, fileName)); displayException.HelpLink = SR.AddRemoveComponentsBadModule; } catch (ReflectionTypeLoadException) { displayException = new Exception(SR.GetString(SR.AddRemoveComponentsTypeLoadFailed, fileName)); displayException.HelpLink = SR.AddRemoveComponentsTypeLoadFailed; } catch (Exception ex) { displayException = ex; } if (displayException != null) { IUIService uis = (IUIService)parentPage.GetService(typeof(IUIService)); if (uis != null) { uis.ShowError(displayException); } else { MessageBox.Show(this, displayException.ToString()); } } } }
public override bool Equals(object o) { ToolboxListViewItem li = o as ToolboxListViewItem; return(li != null && li.Item.Equals(item)); }