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
375
Converting an integer to a color
posted

I'm using the UltraWinTree control in visual basic and I want to set the background of each node based on a value in the datarecord that the node is displaying. Problem is that the data for the color in the record is stored as an integer. I tried the following statement

tvwActions.Nodes.Override.ActiveNodeAppearance.BackColor = (

CType(objRow.Item("Color"), Color))

which produces an error that an integer can't be converted to a color. Any ideas on how to accomplish this?

  • 71886
    Offline posted

    Hello Tigerpaw,

    An approach that you could use in this scenario might be to create an implicit variable which is an Int32 and then pass this variable to the 'FromArgb' method. What this method does is creating the color structure you need from the four 8-bit ARGB components. The value of each component is limited to 8 bits.

    So to summarise with a code sample:

     

    var argb = Convert.ToInt32(150);

    tvwActions.Override.ActiveNodeAppearance.BackColor = Color.FromArgb(argb, argb - 23, argb + 45, argb / 20);

     

    The integers passed in this method are as follows: (alpha, red, green, and blue).

    Please note, we are making efforts to ensure all posts are addressed by an Infragistics expert. We believe that the other community members could benefit from this thread as well.

    Feel free to let me know if I misunderstood your requirement or if you need any additional assistance.