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]))
I'm not sure that I understand the problem; you need to get a .NET Color object in order to create an Infragistics.Documents.Graphics.Color object. There is a Color property on the UltraColorPicker that you can use, or you can parse the RGB values from the Value property yourself.
-Matt
I don't have access to the colorPicker when I'm generating my report. All I have was the value that was saved to the database by the value property of colorPicker. i.e 'Color [Orange]' or, in the event that the color matches a default colour Color '[A=255, R=192, G=0, B=0]'
I've tried to create a .net color (system.drawing.color) from the value 'Color [Orange]' but this doesn't seem possible.
If I'm missing something obvisous please show me,
Thanks!
I'm trying to get this to work look at the following and tell me where I'm going wrong. I don't get any exceptions but I still don't get the colour. If I hard code the colour from RGB it works as I can see the colour on my report. When I use the following it goes back to white!
NOTE: that dsTemplate1.Tables(0).Rows(0).Item("Colour")) has a value of 'Color [Olive]'
Dim myColour As New Infragistics.Documents.Graphics.Color(System.Drawing.Color.FromName(dsTemplate1.Tables(0).Rows(0).Item("Colour"))) headerCustomBackground = New Infragistics.Documents.Report.Background(myColour)
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)
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
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.
>> 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.