Windows Develop Bookmark and Share   
 index > Windows Forms General > PropertyDescriptor.GetValue() => Huh?
 

PropertyDescriptor.GetValue() => Huh?

Hello All, 

  I am trying to write out the properties for the controls placed on my form to an XML file. I think that the following code is close but the line with p.GetValue() does not work. This is not really shocking as GetValue() is defined as "abstract". Fine, but the online help says something like "if you override this class you need a MyPropertyValues method." I have no idea what to put in the method, where it should go, or anything like that.

  I looked online for samples or tutorials but could not find anything that made sense to me. Does anyone know of a source of information or examples for this sort of thing?

XmlTextWriter writer = new XmlTextWriter();
// set up the writer here...

foreach(Control c in myControl.Controls)
{
writer.WriteStartElement("Item");
writer.WriteAttributeString("Name", c.Name);
PropertyDescriptorCollection props = c.GetProperties();
foreach(PropertyDescriptor p in props)
{
writer.WriteStartElement(p.DisplayName);
writer.WriteString(p.GetValue()); // MESSED UP HERE!
writer.WriteEndElement(); 
}
writer.WriteEndElement(); // Item
}
writer.WriteEndElement(); // Dialog


 Thanks in advance.
Steve
MigrationUser 1  Wednesday, May 28, 2003 10:27 AM
I actually already wrote a class to do this...it's pretty simple and doesn't cover every situation, but you might find it useful!  :) 

<a href="http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=de5858f1-db75-4a1e-a86d-b31cb93b0ab1">UISerializer</a>
MigrationUser 1  Monday, June 02, 2003 1:59 PM

You can use google to search for other answers

Custom Search

More Threads

• StyleGuidelines/Best Practices for WinForms
• set Datagrid color of each 4 rows
• Forms Pass Event
• Error creating window handle
• Implementing Keyboard support in windows forms
• Unable to access a row in a table
• create multi form - problem
• Browser Control!!
• ComboBox editing portion not drawing correctly
• Outlook Calendar Look and Feel