How do I manage the wrong data type being sent to a class property? I'm using a property Grid, and I have bound the values to an object (my own, so I can modify the code).
So, for example, I have an object property of type Integer. This is bound to a property Grid value. The user type "Tosh", and an error is displayed telling me the value is incompatible.
I can't see a way to catch the exception, as it occurs as the value is passed to the object property.
This is the extended version of the control from CodeProject.
Property code:
Implementation of the value:Code:Property sizeX() As Single Get Return sSize.X End Get Set(ByVal value As Single) If value > sMax.X Then Throw New System.Exception("Value (" & value.ToString & " is too large. Maximum is " & sMax.X.ToString) Else If value <= 0 Then Throw New System.Exception("Value must be > 0") Else sSize.X = value End If End If End Set End Property
Code:.Item.Add(cLBL_WORLD_X, world, "sizeX", False, cWORLDPROPERTIES, cLBL_WORLD_X_DESC, True)![]()




Reply With Quote