Combobox problem
Dear friends i want to add values in combobox in my c# application and want to maintain these values in it when i open application next time.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Krishna GaradRank #191 · 12.8K reputationPosted Jan 4, 2011, 6:40 PM EST
Mayur Gujrathi85 reputationPosted Jan 4, 2011, 6:54 PM EST
Kevin Aung46 reputationPosted Jan 5, 2011, 11:11 AM EST
Here, you could set up the variables you want to store. Choose your var type or click browse if you don't see one there.
For a combo box, you could store in System.Collections.Specialized.StringCollection.
Say we set up a var called "comboValues" of System.Collections.Specialized.StringCollection type in Settings.settings
in your code (example project name "TestApp"), you could have something like:
using System;
using System.Collections.Specialized;
using TestApp.Properties:
namespace TestApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Settings mySettings = new Settings();
foreach (string val in mySettings.comboValues)
myComboBox.Items.Add(val);
}
private void SaveComboBoxValues()
{
Settings mySettings = new Settings();
StringCollection myValues = new StringCollection();
foreach (var cVal in myComboBox.Items)
myValues.Add(cVal.ToString());
mySettings.comboValues = myValues;
mySettings.Save();
}
}
Mayur Gujrathi85 reputationPosted Jan 6, 2011, 12:13 AM EST