473,386 Members | 1,602 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Serializing objects into application settings

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?
Feb 27 '07 #1
4 3272
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 (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.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/subscripti...t/default.aspx.
==================================================

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

Apr 13 '07 #2
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.
Apr 16 '07 #3
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 (wa****@online.microsoft.com, 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.

Apr 17 '07 #4
Aha... that is the "missing link". Thank you.
Apr 17 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Cristian | last post by:
Hi I have some trouble (on only one developer computer) with the application settings functions... I have posted to the Microsoft.Public.vstudio.setup group but they couldn't help me and asked...
3
by: Nayan Mansinha | last post by:
Hi All How can I store an array of objects in my C# Application.Settings? I have CMyObject class for which an array is created: CMyObject arr = new CMyObject; arr = new CMyObject();...
2
by: Bob | last post by:
The my.settings name space is easy to use to modify User settings from within code, but the application settings can't seem to be modified that easily. I want the user to be able to modify some of...
3
by: Jon Slaughter | last post by:
I wrote an app that needed to save settings such as colors, fonts, etc... after hours of trying to use ConfigurationManager and AppSettings along with a few other things I finally found that I...
0
by: steve | last post by:
I am using vb.net 2005 Express Edition. Application Settings would be a very useful thing, as a global program database that persists; if only it would work! Does anyone know a hack or a...
4
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
I've been toying with the idea that it might be nicer to store all my settings as application settings rather than having to play games with saving and restoring from an external file. However, my...
2
by: Grant Schenck | last post by:
This seems like is should be straight forward but I'm just not getting it. I have a very simple class (see below) which I think should be XML serializable. I have this class defined in my simple...
11
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
I have worked with application settings in VS2005 and C# for awhile, but usually with standard types. I have been trying to store a custom container/class/type in an application setting and I have...
1
by: asedt | last post by:
So i'm using VS 2005 and VB. My ultimate goal is to make a ComboBox with the items from the stored settings. The setting is of the type StringCollection...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.