TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Rano AH
NA
176
111.5k
Saving data using Properties.Settings
Sep 16 2013 2:05 PM
Hi
I have two questions here related to each other, I'll try to explain the problem and make it clear, hope to get the solution as soon as possible.
I have four comboBoxes which being all filled with default format of items each time I run my application.
Suppose that I need to change the current selection of items, and therefore I selected an Item form ComboBox1, another item from ComboBox2, another item from ComboBox3 and one item from comboBox4 and wanted the save this current format using Properties.Settings.
Below is my code, Please have a look and let me know how it is possible to load my stored items automatically next time I run my application. Saving the settings method works fine with me, but when I try to call loadStoredData method in the form load, all four comboBoxes will be empty (null values). Any idea?
Also, What condition I need to set to check if there is a saved data? and in this case the comboBoxes must filled with the saved data (maybe by calling LoadStoredData method) instead of the default format of the comboBoxes. in case of no stored data, then the comboBoxes will display the default format (filled automatically with items using other function (fillComboBoxesByDefault).
//Declaring globaly:
string [] selectedItemsList = new string [4];
string [] MyItems = new string [4];
private string [] saveSettings()
{
String data1 = comboBox1.SelectedItem.ToString();
String data2 = comboBox2.SelectedItem.ToString();
String data3 = comboBox3.SelectedItem.ToString();
String data4 = comboBox4.SelectedItem.ToString();
SelectedItemsList[0] = Properties.Settings.Default.String1 = data1;
SelectedItemsList[1] = Properties.Settings.Default.String2 = data2;
SelectedItemsList[2] = Properties.Settings.Default.String3 = data3;
SelectedItemsList[3] = Properties.Settings.Default.String4 = data4;
Properties.Settings.Default.Save();
MyItems = selectedItemsList;
return MyItems;
}
//This function must load the stored data when I run my applicaion.
private void LoadStoredData()
{
comboBox1.SelectedItem = Properties.Settings.Default.String1;
comboBox2.SelectedItem = Properties.Settings.Default.String2;
comboBox3.SelectedItem = Properties.Settings.Default.String3;
comboBox4.SelectedItem = Properties.Settings.Default.String4;
}
Reply
Answers (
0
)
Show Full calender with checkbox
Special Character Detection in Password security