This is a migrated thread and some comments may be shown as answers.

Error when editing the properties of the type size

1 Answer 65 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Valery
Top achievements
Rank 1
Veteran
Valery asked on 21 Mar 2019, 11:19 AM

we have the following property:

private Size _picSize = new Size(1272, 787);

public Size PicSize
{
     get => _picSize;
     set => value;

}

if in the radpropertygrid for this property to remove the height and semicolon, press <enter>, an error occurs:

System.ArgumentException: Не удается разобрать текст "1000". Ожидаемый формат текста: "Width,Height".
в System.Drawing.SizeConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
в Telerik.WinControls.UI.PropertyGridItem.ConvertValue(Object value, Object& convertedValue)
в Telerik.WinControls.UI.PropertyGridItem.set_Value(Object value)
в Telerik.WinControls.UI.PropertyGridTableElement.EndEditCore(Boolean commitChanges)
в Telerik.WinControls.UI.PropertyGridTextBoxEditor.OnLostFocus()

 

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 22 Mar 2019, 01:10 PM
Hello, Valery, 

I have followed the provided information and setup a sample project to test the specific scenario. Indeed, when you edit the Size property and leave only the width part, an error will occur. Note that the Size property expects (width,height) format. Otherwise, the entered input wouldn't be able to parse to a valid Size. 

The possible solution that I can suggest is either to handle the PropertyValidating event and ensure that the newly entered value is valid and can be parsed to a valid Size or disable entering edit mode for the Size property itself bu edit only the width and height parts of the size. For this case it is necessary to cancel the Editing event. You can find below a sample code snippet: 

private void radPropertyGrid1_Editing(object sender, Telerik.WinControls.UI.PropertyGridItemEditingEventArgs e)
{
    if (e.Item.Label == "PicSize")
    {
        e.Cancel = true;
    }
}

Feel free to use this approach which suits your requirement best.

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Sr.
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.
Tags
PropertyGrid
Asked by
Valery
Top achievements
Rank 1
Veteran
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or