Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
310
ValueBasedAppearance for Enums
posted
I've a column in the ultragrid (wingrid) whose datatype is an enumeration I've defined as follows 

public enum ResultEnum : short

{[EnumDescription("OPEN")]

Open = 1,

[
EnumDescription("WON")]

Won = 2,

[
EnumDescription("LOST")]

Lost = 3,

[
EnumDescription("VOID")]

Void = 4,

[
EnumDescription("DEAD HEAT")]

DeadHeat = 5

}

 I want to set the cell's Forecolor to Green if the Result is WON and to Red if the Result is LOST.  Since the DataType of the column is set to the enum above, in the ValueBasedAppearance designer window, when I try to add a Operator Condition, I am not able to assign a value as whatever I type is treated as a string.  I added a formula condition [Result] = 2 (for Won) and [Result] = 3 (for Lost) and that works.  Is there a way I can use the Enumeration values instead of having to type the integer values? 

Parents
No Data
Reply
  • 469350
    Verified Answer
    Offline posted

    sureshg1972 said:
    I added a formula condition [Result] = 2 (for Won) and [Result] = 3 (for Lost) and that works.  Is there a way I can use the Enumeration values instead of having to type the integer values? 

     

    Yes and no.

    The CalcManager can't access your enum. But you could define your enum for the CalcManager using NamedReferences.

    What I would do is establish some sort of naming convention for the enum, like "ResultEnum_Open", "ResultEnum_Won", "ResultEnum_Lost", etc. Use these names in your formulas. Then at run-time, you use enum.GetValues to get all the possible values of the enum and loop through them and add a NamedReference to the CalcManager for each one using the naming convention and the value of the enum. You will want to do this at run-time, because that way you don't have to update it if you change the enum.

Children