Checkbox Default Value

W

WolfgangD

Hi,
I have got a prblem:

I created a checkbox, this checkbox will get the informations from a
text file :


FileStream mem_name = new FileStream(pfad, FileMode.Open,
FileAccess.Read);
StreamReader read_name = new
StreamReader(mem_name);
string row;
while ((row= read_name.ReadLine()) != null)
{
comboBox1.Items.Add(row);
}

That works!

Now ,
if I select a value I want that this value will be saved......so that
this value is selected at the next program start.

I was trying to to this with an second file:
//SELECTED VALUE IN COMBOOX
string defname = comboBox1.Text;

//path for txt file
string defpath = Application.StartupPath + "\\defserver.txt"
//create file
FileStream fs = new FileStream(defpfad, FileMode.CreateNew);
StreamWriter myStreamWriter = new StreamWriter(fs);

//put the calue inside the textfile
myStreamWriter.WriteLine(defname);
myStreamWriter.Close();




Is this okay ? How can I go on ?


Thanks!!!
Wolfgang
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

WolfgangD said:
Hi,
I have got a prblem:

I created a checkbox, this checkbox will get the informations from a
text file :

I see no checkBox in your code.
Your solution should work, it might not be the best one but it should work
ok.

Do you have any problem with it?
 
W

WolfgangD

Yes,
maybe there is a better way _
Oh sorry i wrote checkboc it is a listbox.

I don`t get it (I am a C# Newbie):
The values inside the listbox werde loading by the values inside the
text-file.
What I want is that if a user select a value, close the apllication.
Start the application again.. the selected value is automatic.
selected.

I tried it with a second text file. If the User selects an value in
the listbox ind the second text-file the value will be stored.


Maybe you van help me ?


Thanks a lot!

Greetings
Wolfgang
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

WolfgangD said:
Yes,
maybe there is a better way _
Oh sorry i wrote checkboc it is a listbox.

I don`t get it (I am a C# Newbie):
The values inside the listbox werde loading by the values inside the
text-file.
What I want is that if a user select a value, close the apllication.
Start the application again.. the selected value is automatic.
selected.

I tried it with a second text file. If the User selects an value in
the listbox ind the second text-file the value will be stored.


You need to save the selected value somewhere a text file should work just
fine. In the Closing method you can extract the value and save it in the
file (you could also use SelectedIndexChanged from the listbox)

Then in the Load event of the form you can check if the file exist if so you
can load the value and after assign the values to the listbox you can set
the selected value.
 

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

Top