Hello, Dmitriy,
By design, when a certain property is
typeof(Color),
RadPropertyGrid creates
PropertyGridColorItemElement. However, if the color is stored in a string property, the default visual item element will be used. You can handle the
CreateItemElement event and specify what item element to be used. However, note that
PropertyGridColorItemElement expects Color type for the value. That is why it would be necessary to convert your string value to a valid Color. Here is a sample code snippet:
private
void
RadPropertyGrid1_CreateItemElement(
object
sender, Telerik.WinControls.UI.CreatePropertyGridItemElementEventArgs e)
{
if
(e.Item.Label ==
"SomeColor"
)
{
e.ItemElementType =
typeof
(CustoPropertyGridColorItemElement);
}
}
public
class
CustoPropertyGridColorItemElement : PropertyGridColorItemElement
{
public
ColorEditorColorBox ColorBox
{
get
{
FieldInfo fi =
typeof
(PropertyGridColorItemElement).GetField(
"colorBox"
, BindingFlags.Instance | BindingFlags.NonPublic);
return
fi.GetValue(
this
)
as
ColorEditorColorBox;
}
}
public
override
void
Synchronize()
{
PropertyGridItem item = (PropertyGridItem)
this
.Data;
if
(item.Value ==
null
|| item.Value.Equals(Color.Empty))
{
this
.ColorBox.BackColor = Color.Empty;
this
.ContentElement.Text =
" "
;
}
else
{
if
(item.Value
is
Color)
{
this
.ColorBox.BackColor = (Color)item.Value;
this
.ContentElement.Text = item.FormattedValue;
}
else
{
string
value = item.Value.ToString();
this
.ColorBox.BackColor = Color.FromArgb(
int
.Parse(value));
this
.ContentElement.Text = item.FormattedValue;
}
}
}
}
I hope this information helps. If you have any additional questions, please let me know.
Regards,
Dess
Progress Telerik
Get
quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers.
Learn More.