PropertyGrid Invalid Property Value

Hi All,

In my custom form designer, I have a property grid. I am having a problem while selecting multiple (>1) controls to change their common property. For example, if I select 2 labels at the same time, and change the size of them, I will get an error message saying "Invalid Property Value", and the details show "Specified cast is not valid." The property then got changed. But when I select only one control to change its property, it's fine. I can't debug where the error occurs. Really frustrated.

Any idea Thanks a lot.



Answer this question

PropertyGrid Invalid Property Value

  • Randy

    Exactly what controls are you using when this happens And what property gives the error

    I just tried with Button and Label and set the Size successfully.

    Whats most likely happening is that one of the controls is offering the same property name, but its Type is different.



  • Bejoy

    Your advice did help me find the problem. It happened when I was trying to trap the ComponentChangedEventArgs (ce). When there are more than one item changed at the same time, an array was captured, so when I was trying to case an array to component, it threw invalidcaseexception. Thanks so much for your help!!!
  • chen2006

    I tried 2 labels, 3 labels, 2 textboxes, ... and other combination of controls, and I tried BorderStyle, Size, BackColor. Actually I developed my project from a sample project, and in the sample project, everything works fine. I'm using the same selection service file, same designer transaction file.

    Thanks for your help.


  • aamir malik

    Thanks for your reply. Basically, for any property of the two selected controls, I got exception properties window exception "Invalid Property Value" with details of "Specified cast is not valid". However, the properties are changed after the exception message. In the code stepping, with the exception, the stepping did not got to PropertyGrid_PropertyValueChanged event. If only one control was selected to change the property value, the stepping goes to PropertyGrid_PropertyValueChanged.
  • RickInHouston

    Sorry for the delayed response -- If you can turn off Just My Code in debugging options and turn on first chance exception catching, this should give you a call stack of who is throwing the invalid cast exception.

    I'm not sure why this is happening unless your designer is changing or shadowing these properties and giving them different Types.

    If you can get a call stack with the person throwing the exception, it might indicate the cause.



  • Xabier Yeregi Hernandez

    Some properties are not "mergable", but the property window should know this and not allow you to edit those properties.

    It could be that changing the size of all the controls causes a problem in some other way. If you can describe more about your error (the form and controls you are selecting), it may shed more light on the problem.



  • PropertyGrid Invalid Property Value