Error when editing the properties of the type size

2 posts, 0 answers
  1. Valery
    Valery avatar
    65 posts
    Member since:
    May 2011

    Posted 21 Mar 2019 Link to this post

    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()


  2. Dess | Tech Support Engineer, Sr.
    Dess | Tech Support Engineer, Sr.  avatar
    4059 posts

    Posted 22 Mar 2019 Link to this post

    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. 

    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.
Back to Top