Hello, I encountered a bug with PropertyGrid when an object property is null.
But it only happens when the object has a simple property, a simple list, and a complex list with a custom control.
I'm attaching a sample project.
To reproduce this bug, run the project and hit the sort button or enter any search strings.
Hello, Jong,
The default PropertyGridValueElement has the following implementation for the Synchronize method: public virtual void Synchronize()
{
this.Text = ((PropertyGridItem)VisualItem.Data).FormattedValue;
}
This covers the cases when the data item is not initialized and can be null. If you use a similar approach for synchronization in the custom AutocompletePropertyGridValueElement that you use, sorting and searching are not expected to throw any exceptions. You should think about covering such cases when the default RadPropertyGrid's implementation is customized.
I believe that the provided information sounds reasonable to you. Should you have further questions please let me know.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
Hello Dess,
Thank you for your reply.
As I noted in the title, this happens only when a property value is not initialized or null.
And your improvement is a workaround to the property initialization, because (item.Instance as TestObject).JoinedTags + string.Empty returns an empty string when JoinedTags is null.
I think even if the property value is null, sorting or searching should throw a null reference exception?
public class AutocompletePropertyGridValueElement : PropertyGridValueElement
{
private StackLayoutElement stackPanel = null;
protected override void CreateChildElements()
{
base.CreateChildElements();
stackPanel = new StackLayoutElement();
stackPanel.StretchHorizontally = true;
RadAutoCompleteBoxElement radAutoCompleteBox = new RadAutoCompleteBoxElement();
stackPanel.Children.Add(radAutoCompleteBox);
this.Children.Add(stackPanel);
}
public override void Synchronize()
{
PropertyGridItem item = this.VisualItem.Data as PropertyGridItem;
foreach (RadAutoCompleteBoxElement radAutoCompleteBox in stackPanel.Children)
radAutoCompleteBox.Text = (item.Instance as TestObject).JoinedTags;
}
}
I have made the following improvement in the custom implementation and it seems to work properly:
public override void Synchronize()
{
PropertyGridItem item = this.VisualItem.Data as PropertyGridItem;
foreach (RadAutoCompleteBoxElement radAutoCompleteBox in stackPanel.Children)
{
radAutoCompleteBox.Text = (item.Instance as TestObject).JoinedTags + string.Empty;
}
}
Could you please give it a try on your end and see whether it will work for your scenario?
I am looking forward to your reply.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.