PropertyGrid Serialize Property of type SystemColor

J

Joe

Hi

I have a propertygrid that I allow the user to pick a system.color and I
want to save to a file to load later
onto the propertygrid. String and bool values work but I am unable to save
colors

Any suggestions???
Thanks


Serializing code
----------------
XmlSerializer mySerializer = new XmlSerializer(typeof(ExcelProperty));

// To write to a file, create a StreamWriter object.

StreamWriter myWriter = new StreamWriter(sFile);

mySerializer.Serialize(myWriter, this);





PropertyGrid Class

-------------------------



[Category("Header")]

[Description("Backcolor data header row")]

public System.Drawing.Color HeaderBackColor

{

get { return cBackColor; }

set { cBackColor = value; }

}

[Category("Data")]

[Description("Alternate row color data rows")]

public bool AlternateRowColoring

{

get { return bAlternateRow; }

set { bAlternateRow = value; }

}
 
J

Joe

Hi

I get no error but the xml is empty for that property that stores
system.color

<AlternateRowColoring>true</AlternateRowColoring>
<AlternateRowColor />
 
P

Patrick Steele

Hi

I get no error but the xml is empty for that property that stores
system.color

<AlternateRowColoring>true</AlternateRowColoring>
<AlternateRowColor />

The "Color" structure has no public settable properties (the R, G, B and
A properties are read-only so they aren't serializable). You'll need to
add an extra property to serialize a Color property. See:

http://tinyurl.com/p7wxv
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top