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
4032
How bind ARGB-value of UltraColorPicker control
posted

Hi all,

I have a dataset-table with column BackColor of type integer and have bound the colorpicker ColorWin32-property to the datasource. It seems that the alpha value gets lost when saving to the database. Choosing color transparent ist restored to color white.

I have tried to bind the colorpicker Color-property instead and to use a datafilter to convert the values. But I get an internal editor converting error:

    InnerException Message: Invalid conversion.
       bei Infragistics.Win.UltraWinEditors.UltraColorPicker.OnValueChanged(EventArgs args)
       bei Infragistics.Win.UltraWinEditors.TextEditorControlBase.OnValueChanged(Object sender, EventArgs args)
       bei Infragistics.Win.EmbeddableEditorBase.RaiseValueChangedEvent()

My datafilter implements to conversions:

 case Infragistics.Win.ConversionDirection.EditorToOwner:
     if ( args.Value == DBNull.Value || args.Value == null || args.Value.Equals( System.DBNull.Value ) )
           return args.Value;

     args.Handled = true;

     Color color = (Color)args.Value;

     // return argb value to tha dataset and to store in db    

     return color.ToArgb();

 case Infragistics.Win.ConversionDirection.OwnerToEditor:
      if ( args.Value == DBNull.Value || args.Value == null || args.Value.Equals( System.DBNull.Value ) )
          return args.Value;

      args.Handled = true;

      // return color class to the bound color-property
      return (Color)args.Value;

Does anybody can point me in the right direction to achieve this.

Regards

Markus

Parents
No Data
Reply
  • 469350
    Offline posted

    Hi Markus,

    The ColorWin32, ColorHtml, and ColorOle properties are all handled by the DotNet framework's ColorTranslator class. I did a little research and it looks like none of these support an alpha channel in the color.

    You can see this yourself, if you like:


                Color color = Color.FromArgb(128, 128, 128, 128);
                int i = ColorTranslator.ToWin32(color);
                Color color2 = ColorTranslator.FromWin32(i);

    If you run that code and examine color2, you can see the alpha is 255.

    The good news is that the Color class itself has methods for converting a color to an int and vice versa while maintaining the alpha channel. So you can achieve what you want using Color.FromArgb and color.ToArgb.

    So what you can do is use the Parse and Format events of the Binding to do the conversion.

    I have attached a small sample project here demonstrating how it's done.

    WindowsFormsApplication9.zip
Children