Sir,
I have set style of a UltraWinGrid column as Color. How to get the selected Color's RGB value from that cell.
Kindly help me in this regard
Is the underlying DataSource's type for that column also a color? If that is the case, you could just access the cell's Value and cast it to a Color. From there, you can access the R, G, and B properties. If it is stored as a string (i.e. the ToString of the color), then I don't think that there's a simple way to get that value back into a .NET color unless it is a known color, but you could parse that string for the A, R, G, and B values and create the color yourself.
-Matt
i have column with ColumnStyle.Color and then choose some color cell.Value = Color["ColorName"] or Color[A=, R=,G=,B=]. and so then cast it to a Color you take some color, but ARGB properties will be 0. How correct column properties to have a normal cell.value?
I want to take RGB properties to convert it in hex, maybe can make this right away?
PS: sorry for my English
It sounds like the DataType of the column is a string, in which case you will not be able to cast the value directly into a color and get the value as such. For example, you could have a cell created by:
row[0] = Color.Red.ToString();
This will result in a cell value of "Color [Red]'. If you try to parse this into a color, such as through Color.FromName(), you will still not have a known color. You would have to parse out the value between [ ] and then pass that value into the Color.FromName() method. Unfortunately, this is more difficult when you're dealing with an unknown color (i.e. if the color does not have a name that .NET recognizes), since you could have a string value of "Color [A=255, R=255, G=128, B=34]", as an example. In this case, you would have to parse out each value yourself, since I'm not aware of a method that will parse this back into a Color. The easiest solution is, by far, to make sure that the underlying DataType of the column is a Color and not a string.
As for converting RGB to hex, you could look into the System.Drawing.ColorTranslator.ToHtml method.
Thanks Matt, that's exactly what we've set up. It works well.
As Mike pointed out in the posts that you linked, there really is no way for the grid to automatically do this. This doesn't have anything to do with the grid, but rather the way that the Color class works and how the data is stored. Your best option is to use a DataFilter, as pointed out in the same thread, though I also think that the ColorTranslator is the best bet, allowing you to store the string-based hex value of the color.
I'm also faced with this issue.
In our MS SQL database, we will be storing values selected by an UltraColorPicker. There is no MS SQL "color" type for the column.
Setting the column's type to nvarchar() results the same way as the original poster.
What are my best options for this scenario? We want to use direct data-binding between the grid and the datasource.
Thanks
PS - I've read this: http://forums.infragistics.com/forums/p/26133/95919.aspx#95919but can't imagine there's no way to do a simple mapping.