Unfortunately I'm using an older version of the winforms controls, but just in case someone can help..
I'm validating in the property view, but I can't get an error message to show. I even tried to set Description until I worked out the error message issue, but that doesn't show either. (I have the help panel showing).
I have a delegate doing the property validation, which returns me an error string if invalid. The string is being returned correctly. See below for my code; I've only changed a name or two.
private
void
OnValidating(
object
sender, PropertyValidatingEventArgs e)
{
var item = e.Item
as
PropertyGridItem;
if
(item ==
null
)
return
;
if
(_validateProperty !=
null
)
{
var item = GetViewModelItem(sender);
var error =
""
;
var valid = _validateProperty(item, e.Item.Name, e.NewValue
as
string
,
out
error);
if
(!valid)
{
// TODO: error message not showing
item.ErrorMessage = error;
}
e.Cancel = !valid;
}
}
6 Answers, 1 is accepted
Could you specify the exact version number that you are using?
Please note that the description is displayed in the help panel. The error message is shown when you are hovering the red exclamation mark. I have attached a small project that shows how this works.
I am looking forward to your reply.
Regards,
Dimitar
Progress Telerik
Seems to be 2017.3.912.40
I have tested it with this version and it appears to work correctly on my side (see attached video). Could you please let me know what I need to change in the test project in order to reproduce the undesired behavior? Or perhaps you want to achieve something else?
I am looking forward to your reply.
Regards,
Dimitar
Progress Telerik
I found something that fixed it. I had ShowItemToolTips set to False on my PropertyGrid control. I set it to True and can see the message.
However, I don't get the message appearing in the help area, it appears as a tooltip, like in the documentation. This is actually my preference, so that's fine, but I'm not sure why yours is different. The only problem is that the user must hover over a very small area, the "!" character, to see the message.
I also tried a fresh project similar to yours, and I still get the message as a tooltip.
A sample project would've been good too.
This is the default behavior and the error message is displayed in the tooltip. The help panel displays the string from the description attribute. You can use the following approach in order to increase the area where the tooltip appears:
private
void
RadPropertyGrid1_ToolTipTextNeeded(
object
sender, Telerik.WinControls.ToolTipTextNeededEventArgs e)
{
var item = sender
as
PropertyGridItemElement;
if
(item !=
null
)
{
var data = item.Data
as
PropertyGridItem;
if
(data.ErrorMessage !=
null
)
{
e.ToolTipText = data.ErrorMessage;
}
}
}
I hope this will be useful. Let me know if you have additional questions.
Regards,
Dimitar
Progress Telerik