This is what im trying to do
http://msdn.microsoft.com/en-us/library/cftf714c.aspx
I just want to save the machines i input in so i dont have to re-type them in every time i run the program.
thank you for your time.
if you need me to send you the program i will.
Ryan AlfordPosted Dec 30, 2008, 7:05 PM
Ok, so the first things you will need to do is add to the Settings. This can be done by clicking on the Project, then going to View --> Property Pages. Click on the "Settings" tab, and you will see the grid-like page.
For the "Name", type in the name of the setting. For the "Type", select the type of the setting(string, int, connectionString, etc.), Set the "Scope" to "User"(this allows for editing of the values...setting it to "Application" makes it read-only), and leave the "Value" blank. Now click the save button at the top.
For my example, I am going to create 3 settings named "TextFromTextBox1", "TextFromTextBox2", "TextFromTextBox3", and they will all have a "Type" of "string".
In my example, I have created a simple Windows app that has 3 textboxes on the form, and they are all named the default name("textBox1", etc.). I also have a "Save" button.
I have created two events: the Form_Load event for the form, and the Click event for the button.
In the Form_Load, we are going to read from the settings file to get the text that was saved:
private void Form1_Load(object sender, EventArgs e)
{
textBox1.Text = Properties.Settings.Default.TextFromTextBox1;
textBox2.Text = Properties.Settings.Default.TextFromTextBox2;
textBox3.Text = Properties.Settings.Default.TextFromTextBox3;
}
As you can see, the Settings that you created are now actual properties of the "Properties.Settings.Default" class. This makes them very easy to interact with.
Now, to save the values, you would simply set the text from the textbox to the property and save:
private void btnSave_Click(object sender, EventArgs e)
{
Properties.Settings.Default.TextFromTextBox1 = textBox1.Text;
Properties.Settings.Default.TextFromTextBox2 = textBox2.Text;
Properties.Settings.Default.TextFromTextBox3 = textBox3.Text;
Properties.Settings.Default.Save();
}
Now build and run the application. The textboxes will be blank the first time because we haven't saved anything. Type something in all the boxes, then click Save. Close the application, then run it again, and you will see the text that you typed will appear in the textboxes.
Let me know if you have any questions.
RyanPosted Dec 30, 2008, 8:35 PM
RyanPosted Dec 30, 2008, 6:21 PM
Ryan AlfordPosted Dec 30, 2008, 4:58 PM
RyanPosted Dec 30, 2008, 3:12 PM
Im having issues with this. When i click on my program and run it i click on add machine next a form pops up and i enter in my server name for the server i want to monitor my user name and password once that is done it shows back up in the form1 on the datagridview with cpu , mem and hdd information updates every 5 seconds my issue is when i close the proram my machine gos awway in the datagridview and i have to once again go through and click add machine etc.. so how is it possible to do this with in my prog so wheni close it and reopen it my input stay s in the datagridview?
Bechir BejaouiPosted Dec 30, 2008, 1:18 PM
RyanPosted Dec 30, 2008, 1:05 PM
oh man cool i seen this the other night and im just in over my head noob im trying to learn as i go... I cant just read a book about programming i have to be in the deep in first and then it makes sense to me because i start to see things work. I look at the c# learn programming books for refference. Thank you i will read this more in depth and get back to you if i have any questions i really thank you again for the response!
-Summey
Bechir BejaouiPosted Dec 30, 2008, 12:51 PM
http://www.c-sharpcorner.com/UploadFile/yougerthen/204082008064658AM/2.aspx
If you're satisfied please mark it as answered and don't forget to give your article rate