I've a colorPicker control in my grid. The issue comes when I try to use the value of the column. I want to use it with document reporting to set colours on a report. Issue is that I can't find a way to create an instance of Infragistics.Documents.Graphics.Color from the saved value.The value of the colour may either be RGB value or text! Ideally I would override to always save the RGB value not the text representation. Is there a way to do this? I don't care if it displays text representations to the user. It seems quite ridiculous that the value of ColorPicker control cannot be used to create an instance of Infragistics.Documents.Graphics.Color directly.All I want to do is the following : -headerCustomBackground = New Infragistics.Documents.Report.Background(New Infragistics.Documents.Graphics.Color([my colour picker value]))
>> Mike, can you point to a short example of how to use a DataFilter on the ColorPicker to convert from a numeric to a Color and back?
[Edit: I dug around and found one: http://forums.infragistics.com/forums/p/26133/95919.aspx#95919]
It's inconvenient to do it like that, but I understand the reasoning.
Matt, I completely see your point about the source of the problem being the System.Drawing.Color.ToString() function missing a complementary FromString(). Sure would have made life easy if they had thought to do it. It can be added as an Extension Method to the class, but still a hack job.
aim123 said:Maybe there is a way to alter the way the colorPicker saves the value.
When embedded in a grid, the value it returns is determined by the data type of the column. The fact that the Color.FromName method doesn't handle the values it returns from its own ToString method is a shortcoming of that type, not the ColorPickerEditor.
Why store a color as a string? Personally, I would not use a string for a color, i would use a numeric value and then use a DataFilter on the ColorPicker to convert from a numeric to a Color and back.
You don't even have to write the code to convert to and from a numeric, you can use the ColorTranslator class to do it for you and store either am HTML, Ole, or Win32 color.
OK, I got this working with the most hideous hack. Seems that you need to convert the string to use FromName(). I can't believe that there isn't a better way than this. Its a joke!Maybe there is a way to alter the way the colorPicker saves the value. If it just consistently saved a delimited string with RGB values it'd be fine!Anyhow here's my hack for those with the same problem...
Dim strValue As String = dsTemplate1.Tables(0).Rows(0).Item("Colour") strValue = strValue.Replace("Color", "") strValue = strValue.Replace("[", "") strValue = strValue.Replace("]", "") strValue = strValue.Replace(" ", "") If dsTemplate1.Tables(0).Rows(0).Item("Colour").ToString.Contains(",") Then headerCustomBackground = New Infragistics.Documents.Report.Background( _ New Infragistics.Documents.Graphics.Color( _ strValue.Split(",")(1).Replace("R=", "").Trim, _ strValue.Split(",")(2).Replace("G=", "").Trim, _ strValue.Split(",")(3).Replace("B=", "").Trim)) Else Dim dotNetColour As System.Drawing.Color = System.Drawing.Color.FromName(strValue) Dim myColour As New Infragistics.Documents.Graphics.Color(dotNetColour) headerCustomBackground = New Infragistics.Documents.Report.Background(myColour) End If
Can someone please provide a specific example to convert both values of format 'Color [A=255, R=234, G=123, B=125]' and 'Color [Orange]' to an actual instance of Infragistics.Documents.Graphics.Color?
I've tried System.Drawing.Color.FromName yet this does not give me anything!
The following does not work!
Dim dotNetColour As System.Drawing.Color = System.Drawing.Color.FromName(dsTemplate1.Tables(0).Rows(0).Item("Colour")) Dim myColour As New Infragistics.Documents.Graphics.Color(dotNetColour) headerCustomBackground = New Infragistics.Documents.Report.Background(myColour)