How to get a property value back?

  • Thread starter Thread starter Özden Irmak
  • Start date Start date
Ö

Özden Irmak

Hello,

In one scenario, I saved a property of my windowsforms control to an
datatable field which has a type of Object. Let's say this property is
'Size' an when I try to set it back it gives me error saying that 'Object
type cannot be converted to target type'.

Any suggestion?

Thanks in advance...

Regards,

Özden
 
Is the Size converted to a string using ToString()? If so it cannot be
converted back.

I found it necessary to store Size values using its TypeConverter i.e.

TypeConverter conv = TypeDescriptor.GetConverter(typeof(Size));

then:
string s = conv.ConvertToString(size);
and
Size size = (size)conv.ConvertFromString(s);

I do this from memory, so the syntax or method names may be incorrect ;)

HTH

Paul Wardle.
 
Hello Paul,

Thanks for the suggestion...I could get it work but I need some more help...

While I save the properties, I use a generic method to save all the public
properties of a control which can be both read/write. I came across with an
error in it...

i.e. when this propety is 'Image', I can't restore it back as it gives me an
error saying 'Can't convert string to Image by ImageConverter'. And the non
convertable string is '(none)'.

Do you have any suggestion for that?

Regards,

Özden
 
Back
Top