Im unsure about how i can use a dictionary i create when i click a button which mean that i cannot reference to it from within another function. This is probably very basic, but i simply cannot remember how this is done.
This is the button that opens up a file dialog, which then reads each line inside the file, and stores the contents inside the dictionary:
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "Mod Pack Configuration file|*.mcf";
openFileDialog1.Title = "Load Mod Pack Configuration File";
openFileDialog1.ShowDialog();
if (openFileDialog1.FileName != "")
{
Dictionary<string, string> loadfile =
File.ReadLines(openFileDialog1.FileName)
.Select(line => line.Split(';'))
.ToDictionary(parts => parts[0], parts => parts[1]);
}
}
Then afterwards i load a function, that places the loaded files, strings inside different controls within the form. However the below code doesnt work as "loaddfile" is not found:
public void getDefaultSettings()
{
if (Properties.Settings.Default.modsDestDropDown != "")
{
modsDestDropDown.SelectedIndex = Convert.ToInt32(loadfile['modsDestDropDown']);
}
}
I could ofcourse write the function inside the button1 click event instead, but since i use this function across the program in other places, it would then give me some trouble later