B
Brett Romero
I'm trying to supply an enum value to an enum property but get a
specified cast is not valid error:
fr.CompareC =
(Comparison)this.cmbCCountComparison.Items[this.cmbCCountComparison.SelectedIndex]
Above errors out. In the fr class is:
public enum Comparison{Equal, Greater, Less};
private Comparison _CComparison = Comparison.Greater;
public Comparison CompareC
{
get{return _CComparison;}
set{_CComparison=value;}
}
The combo box has values:
All
Equal
Greater
Less
In the above scenario, it is returning "Greater". The enums have to
stay in place at this point so what ever the solution is, it will need
to work with the enums. Is there a way to do this without getting into
elaborate lookups? Why doesn't the cast work?
Thanks,
Brett
specified cast is not valid error:
fr.CompareC =
(Comparison)this.cmbCCountComparison.Items[this.cmbCCountComparison.SelectedIndex]
Above errors out. In the fr class is:
public enum Comparison{Equal, Greater, Less};
private Comparison _CComparison = Comparison.Greater;
public Comparison CompareC
{
get{return _CComparison;}
set{_CComparison=value;}
}
The combo box has values:
All
Equal
Greater
Less
In the above scenario, it is returning "Greater". The enums have to
stay in place at this point so what ever the solution is, it will need
to work with the enums. Is there a way to do this without getting into
elaborate lookups? Why doesn't the cast work?
Thanks,
Brett