Best way to save user level Control history?

J

John H.

I am creating a large complex C# WinForm app under VS2008. I have
several custom controls where I need to save the history of user
entries. For example a search text entry box where I save the last 20
entries on a per user basis.

I had originally, thought that creating a .settings file for this
purpose would be the way to go. But, lists are difficult to work with
programmatically as Property settings.
What I have done is saved the history into a
System.Collections.Specialized.StringCollection object and then write
or read them to a disk folder with a BinaryFormatter.Serialize()
or .Deserialize object. I name the individual files in a way that
identifies the App, Form, Control, and user.

This works well, but it seems to me there may be a more straight
forward way to accomplish this. Is there a better way to track user
control history from session to session? Is there a mechanism built
into the .Net framework to handle this that I am not understanding?

Thanks,
John
 
P

Peter Duniho

John said:
I am creating a large complex C# WinForm app under VS2008. I have
several custom controls where I need to save the history of user
entries. For example a search text entry box where I save the last 20
entries on a per user basis.

I had originally, thought that creating a .settings file for this
purpose would be the way to go. But, lists are difficult to work with
programmatically as Property settings. [...]

Perhaps you could be more specific. I know it's possible to store lists
of strings with the Designer-provided Settings class, because I've done
it before. At the very least, you can just store some kind of delimited
string that you can turn back into a list (e.g. using String.Split()),
and my recollection is that it actually supports collections directly.

What trouble did you have exactly trying to store your lists in the
Settings class?
[...]
This works well, but it seems to me there may be a more straight
forward way to accomplish this. Is there a better way to track user
control history from session to session? Is there a mechanism built
into the .Net framework to handle this that I am not understanding?

I'm not sure what you mean here. You have to store the data somewhere.
You can definitely store it in the Settings class, but if not there,
it's not like there's any more convenient way to persist data between
session. The whole point of the Settings class is for it to be the
"convenient" way.

Pete
 
J

John H.

Hi Pete,

Thanks for the feedback. I think I should go back to the root of the
problem.

I can manually create a property in the applications .settings file of
type System.Collections.Specialized.StringCollection. How every I
have not been able to get the code to work to do this programmatically
at run time. I would be hugely appreciative if somebody could post a
code snippet on how to do this.

All of the examples that I find are based on simple types. When I try
to modify them work with a StringCollection type I get an error that I
can not use that type in this context. I am trying to avoid using a
single delimited string and string.split() because I want to avoid any
conflicts between a delimiting character and any characters the user
may enter.

Thanks,
John
 
P

Peter Duniho

John said:
Hi Pete,

Thanks for the feedback. I think I should go back to the root of the
problem.

I can manually create a property in the applications .settings file of
type System.Collections.Specialized.StringCollection. How every I
have not been able to get the code to work to do this programmatically
at run time. I would be hugely appreciative if somebody could post a
code snippet on how to do this. [...]

Unfortunately, "how to do this" is so trivial, it's not likely a code
example will help you. I've posted one below, but it's hardly instructive.

If you continue to have trouble with this, it will be better if you post
_your_ code example showing what you're trying to do, so that whatever
mistake in your attempt exists, it can be pointed out.

Pete


For the example below, add an item to the project's "Settings" named
"StringCollectionSetting", make the type of the setting
"System.Collections.Specialized.StringCollection", and add some strings
to the collection.


using System;
using TestStringCollectionSettings.Properties;

namespace TestStringCollectionSettings
{
class Program
{
static void Main(string[] args)
{
int istr = 0;

foreach (string str in
Settings.Default.StringCollectionSetting)
{
Console.WriteLine((istr++).ToString() + ": " + str);
}

Console.ReadLine();
}
}
}
 

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

Similar Threads

Windows XP Prohibit record run history 0
Clear WebBrowser history. 1
What is the best way to do this 1
User Control 6
WebBroswers Control -> History 3
about user control 3
Application settings not being saved automatically 4
History 6

Top