Hi @Dineshkumar.S ,Welcome to Microsoft Q&A.
There are several methods to choose from. You can continue to choose built-in, or you can choose to use a database, or you can use the registry.
Since you used the built-in before, I also show you the usage of the built-in:
You can create different config files for different users.
When a user logs in, just call different config files according to the user.
Just for reference:
You also need to consider encryption, and create config for each user, you can put the config address in the property, etc.
using System.Configuration;
namespace WinFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string aConfigPath = @"C:\Users\Administrator\source\repos\WindowsFormsApp8\WinFormsApp1\Config\a.config";
string bConfigPath = @"C:\Users\Administrator\source\repos\WindowsFormsApp8\WinFormsApp1\Config\b.config";
private void UpdateComboBoxSelection(string configPath, string key, ComboBox comboBox)
{
ExeConfigurationFileMap configMap = new ExeConfigurationFileMap { ExeConfigFilename = configPath };
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None);
comboBox.SelectedIndex = Convert.ToInt32(config.AppSettings.Settings[key].Value);
}
private void SubmitComboBoxSelection(string configPath, string key, ComboBox comboBox)
{
ExeConfigurationFileMap configMap = new ExeConfigurationFileMap { ExeConfigFilename = configPath };
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None);
config.AppSettings.Settings[key].Value = comboBox.SelectedIndex.ToString();
config.Save();
}
private void button1_Click(object sender, EventArgs e)
{
string textBoxValue = textBox1.Text.Trim();
if (textBoxValue == "a")
{
UpdateComboBoxSelection(aConfigPath, "C1SelectedItem", comboBox1);
UpdateComboBoxSelection(aConfigPath, "C2SelectedItem", comboBox2);
}
else if (textBoxValue == "b")
{
UpdateComboBoxSelection(bConfigPath, "C1SelectedItem", comboBox1);
UpdateComboBoxSelection(bConfigPath, "C2SelectedItem", comboBox2);
}
}
private void button2_Click(object sender, EventArgs e)
{
string textBoxValue = textBox1.Text.Trim();
if (textBoxValue == "a")
{
SubmitComboBoxSelection(aConfigPath, "C1SelectedItem", comboBox1);
SubmitComboBoxSelection(aConfigPath, "C2SelectedItem", comboBox2);
}
else if (textBoxValue == "b")
{
SubmitComboBoxSelection(bConfigPath, "C1SelectedItem", comboBox1);
SubmitComboBoxSelection(bConfigPath, "C2SelectedItem", comboBox2);
}
}
}
}
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.