private static object[] UpdateTagListBox(Tag category, DoubleListBox listBox) { object[] availableTags = FetchTagsForCategory(category).ToObjectArray(); listBox.AssignSecondaryList(availableTags); return availableTags; }
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { var editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); var listBox = new DoubleListBox(); Tag[] categories = FetchAllCategories(); listBox.AssignFlattenedSecondaryList(CatalogTagRegistry.AllTags().ToObjectArray()); Tag currentlySelectedTag = ExtractTag(value); Tag currentCategory = GetCurrentCategory(currentlySelectedTag); listBox.AssignPrimaryList(categories.ToObjectArray()); AssignSelectedIndex(categories.ToObjectArray(), currentCategory, index => listBox.PrimarySelectedIndex = index); object[] availableTags = UpdateTagListBox(currentCategory, listBox); AssignSelectedIndex(availableTags, currentlySelectedTag, index => listBox.SecondarySelectedIndex = index); listBox.PrimaryItemSelected += (sender, args) => { int selectedIndex = listBox.PrimarySelectedIndex; Tag selectedCategory = categories[selectedIndex]; UpdateTagListBox(selectedCategory, listBox); }; listBox.SecondaryItemSelected += (sender, args) => editorService.CloseDropDown(); editorService.DropDownControl(listBox); return listBox.SecondarySelectedItem ?? value; }