Skip to content

Commit

Permalink
EnumDropDown: bug fix where cached value wasn't updated on selected i…
Browse files Browse the repository at this point in the history
…tem changed
  • Loading branch information
RiJo committed Apr 12, 2018
1 parent ea3e36a commit b41d0cc
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions UserInterface/Controls/EnumDropDown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public partial class EnumDropDown : ComboBox
protected class ComboboxItem
{
public string Text { get; set; }
public long Value { get; set; }
public Enum Value { get; set; }

public override string ToString()
{
Expand All @@ -46,6 +46,7 @@ public EnumDropDown()
InitializeComponent();

DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
SelectedIndexChanged += (sender, e) => { enumValue = ((ComboboxItem)SelectedItem).Value; };
}

public Func<Enum, string> EnumText
Expand Down Expand Up @@ -77,7 +78,7 @@ public Type EnumType

Items.Clear();
foreach (Enum item in Enum.GetValues(value))
Items.Add(new ComboboxItem() { Value = item.GetInt64(), Text = (EnumText != null) ? EnumText(item) : item.ToString() });
Items.Add(new ComboboxItem() { Value = item, Text = (EnumText != null) ? EnumText(item) : item.ToString() });
}
}

Expand All @@ -95,12 +96,11 @@ public Enum EnumValue

if (value == enumValue)
return;
enumValue = value;

long numeric = value.GetInt64();
foreach (ComboboxItem item in Items)
{
if (item.Value != numeric)
if (item.Value.GetInt64() != numeric)
continue;

SelectedItem = item;
Expand Down

0 comments on commit b41d0cc

Please sign in to comment.