❔ UITypeEditor with DropDown Bitwise Enum Selector
Hi. I'm having trouble getting the following code to work. Any ideas? It's meant to return a bitwise enum.
namespace stigzler.Winforms.Base.Editors
{
internal class FlagsEditor : UITypeEditor
{
UIElements.ListBox editor = null;
// our editor is a Drop-down editor
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.DropDown;
}
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
if (provider != null)
{
// use windows forms editor service to show drop down
IWindowsFormsEditorService edSvc = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
editor = new UIElements.ListBox();
editor.SelectionMode = SelectionMode.MultiExtended;
// prepare list
editor.DataSource = Enum.GetValues(typeof(EllipsisFormat));
// show drop down now
edSvc.DropDownControl(editor);
// now we take the result
EllipsisFormat flags = 0;
foreach (var item in editor.SelectedItems)
{
flags |= (EllipsisFormat)item;
}
value = flags;
}
return (EllipsisFormat)value;
}
}
}
namespace stigzler.Winforms.Base.Editors
{
internal class FlagsEditor : UITypeEditor
{
UIElements.ListBox editor = null;
// our editor is a Drop-down editor
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.DropDown;
}
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
if (provider != null)
{
// use windows forms editor service to show drop down
IWindowsFormsEditorService edSvc = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
editor = new UIElements.ListBox();
editor.SelectionMode = SelectionMode.MultiExtended;
// prepare list
editor.DataSource = Enum.GetValues(typeof(EllipsisFormat));
// show drop down now
edSvc.DropDownControl(editor);
// now we take the result
EllipsisFormat flags = 0;
foreach (var item in editor.SelectedItems)
{
flags |= (EllipsisFormat)item;
}
value = flags;
}
return (EllipsisFormat)value;
}
}
}
1 Reply
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.