Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / August 2007

Tip: Looking for answers? Try searching our database.

Checkbox Default Value

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
WolfgangD - 28 Aug 2007 13:40 GMT
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
Ignacio Machin ( .NET/ C# MVP ) - 28 Aug 2007 16:05 GMT
Hi,

> 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?
WolfgangD - 29 Aug 2007 09:12 GMT
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
Ignacio Machin ( .NET/ C# MVP ) - 29 Aug 2007 14:23 GMT
Hi,

> Yes,
> maybe there is a better way _
[quoted text clipped - 9 lines]
> 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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.