Cameron Kloot

hi,
in my program i make settings and then load them into a checkedlistbox when the program restarts. this is what i am doing:

public Form1()
{
InitializeComponent();
foreach (object loadItem in Settings.Default.Context)
{
checkedListBox1.Items.Add(loadItem); //Load settings
}
}

Settings.Default.Context.Add(textBox1.Text, textBox2.Text); //new settings string with attributes

it doesnt work all it loads is System.Collections.Dictionary Entry
thanks




Re: Visual C# Express Edition Settings problem

Figo Fei - MSFT

Hi,

As far as I know, you must get their value one by one using Properties.Settings.Default.XXX (XXX refer to setting name)

Thanks






Re: Visual C# Express Edition Settings problem

anubisascends

You will need to set your setting 'Context' to the type - System.Collection.Specialized.StringCollection.

Then place all of your items that you want in the collection.

Then you can use the following code to get it to fill the box:

Code Snippet

private void fillCheckedList()

{

Properties.Settings appSettings = new Properties.Settings();

foreach(string item in appSettings.Context)

{

checkedListBox1.Items.Add(item);

}

}

Then place the following in your form load event:

Code Snippet
fillCheckedList();






Re: Visual C# Express Edition Settings problem

Cameron Kloot

well,
there is an exception on the string item: Unable to cast object of type 'System.Collections.DictionaryEntry' to type 'System.String'.
and when i change it to object, it does the same thing as my code did
is there a better way to store data like just strings
thanks






Re: Visual C# Express Edition Settings problem

anubisascends

Try using the System.Collections.Specialized.Stirngcollection as I stated in my post




Re: Visual C# Express Edition Settings problem

Cameron Kloot

how would i do that

thanks






Re: Visual C# Express Edition Settings problem

anubisascends

Double click on the settings.settings file to open it and change the setting type to the correct type.

Becareful, when you change types, you loose the data, so copy it to notepad first.






Re: Visual C# Express Edition Settings problem

Cameron Kloot

um. i double clicked the settings.settings but it ddnt have any options. all it had where the "Name" "Type" "Scope" and "Value". there is no way on that tab that i can see to change anything. only make a new settings.
thanks






Re: Visual C# Express Edition Settings problem

anubisascends

How are you creating your settings




Re: Visual C# Express Edition Settings problem

Figo Fei - MSFT

Hi, Cameron

First, try to drop down the type column (dropdownlist) of your setting in settings.settings to System.Collections.Specialized.StringCollection (as anubisascends said) and add some values

You'll see something like the following code added to the settings.designer.cs:

Code Snippet

http://www.w3.org/2001/XMLSchema-instancehttp://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</A< A>>"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
'>http://www.w3.org/2001/XMLSchema">http://www.w3.org/2001/XMLSchema"">
; value1
value2
value3
value4
")]
public global::System.Collections.Specialized.StringCollection Setting {
get {
return ((global::System.Collections.Specialized.StringCollection)(this["Setting"]));
}
set {
this["Setting"] = value;
}
}

And some corresponding xml code added to app.config.

Then you can use the following code in your program:

Code Snippet

foreach (string item in Properties.Settings.Default.Setting)
{
checkedListBox1.Items.Add(item);
}

OR

Code Snippet
Properties.Settings appSettings = new Properties.Settings();
foreach (string item in appSettings.Setting)
{
checkedListBox1.Items.Add(item);
}

Thanks






Re: Visual C# Express Edition Settings problem

Cameron Kloot

ok, i think there is a communication problem. i make values for the settings file DURING runtime. those value need to be stored somewhere once the program shuts down. i was trying to use the settings file. would that work then, when i run the app again i need it to scan the settings file, or whatever i am using, and add to the checkedlistbox the item in the settings file. should i be using a different kind of storage system or what
thanks






Re: Visual C# Express Edition Settings problem

jrboddie

Are you remembering to save the setting file before exiting your program

Properties.Settings.Default.Save();





Re: Visual C# Express Edition Settings problem

Cameron Kloot

i tried that, but it still doesnt work
isnt there another way to store strings like in a file or something
thanks






Re: Visual C# Express Edition Settings problem

jrboddie

Trying it is not a option--you must do it or the Settings file will not be updated.

Let's see if we can make this work for you. What does your current code look like





Re: Visual C# Express Edition Settings problem

Cameron Kloot

public Form1()
{
InitializeComponent();
foreach (object load in Settings.Default.Context)
{
checkedListBox1.Items.Add(load);
}
private void okB_Click(object sender, EventArgs e)
{
checkedListBox1.Items.Add(textBox2.Text);
Settings.Default.Context.Add(textBox1.Text, textBox2.Text);
Properties.Settings.Default.Save();
}
that's basically what it says.
thanks