Serializing objects into application settings

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have been experimenting with how to properly store objects into persistent
application settings in user.config. I have read everything I could on MSDN
(and elsewhere) and I have successfully stored objects of type String,
DateTime, and ArrayList, for example.

So I then tried an unbound DataGridView but it serialized with a null value.
I tried the DataSource of the DataGridView; also null. I was going to try
DataGridViewRowCollection, since the debugger showed that does have some
data, but when I attempt to create a setting from the settings pane of the
properties page in Visual Studio 2005, it does not have
System.Windows.Forms.DataGridViewRowCollection as an available choice.

The key, as I understand it, is in this MSDN statement:
"Application settings can be stored as any data type that is XML
serializable or has a TypeConverter that implements ToString/FromString."

So how do I tell if a class is XML serializable or has the right kind of
TypeConverter?
 
Hi Michael,

The short answer to your question is: it's not possible to store the
DataGridView in Settings.

For a long discussion and causes, please see following thread replied by my
colleague Kevin: http://www.thescripts.com/forum/thread480241.html

To tell if a class is XML serializable, the class must implement
IXmlSerializable interface.

Please reply here to let me know if you need further information on this.

By the way, your several posts are not posted using your nospam alias
therefore they're not shown up in our tool, that's why this reply is so
late. Sorry for the inconvenience caused.

Sincerely,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
I reviewed the thread you mentioned, but there is a lot left unsaid there.
So I understand that one cannot store a DataGridView but must instead store
an underlying DataSource. So I tried a simple test of creating a DataTable,
setting the DataGridView.Datasource to that DataTable, then storing that
DataTable into a setting. The program executed, but the value in the
user.config file was empty.
 
Hi,

You need to use a DataSet instead of a DataTable to store the data in
Application Settings.

DataSet is a special case that can be serialized into XML.

1) Change the data type of your setting variable into System.Data.DataSet
2) Create a new DataSet and add your DataTable to it:

DataSet ds = new DataSet();
ds.Tables.Add(myDataTable);


Hope this helps.


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top