So I had help in getting my code to work, turns out I had something missing in my Combobox control.
What I'm trying to achieve:
I'm selecting a file via a drop-down list, once selected, my RichTextBox
shows the contents of the entire file.
I want to be able to change a line in here, using the RichTextBox
, I then have a Save button, once I click this, I want my changes saved to the file I've selected via the drop-down list.
My code thus far:
public ConfigChanger()
{
InitializeComponent();
LoadconfigList();
this.configList.SelectedIndexChanged += new System.EventHandler(this.configList_SelectedIndexChanged);
}
void LoadconfigList()
{
configList.Items.Clear();
string[] files = Directory.GetFiles(@"d:\monitors.d\");
foreach (string file in files)
configList.Items.Add(Path.GetFileNameWithoutExtension(file));
}
private void configList_SelectedIndexChanged(object sender, EventArgs e)
{
string fileName = (string)configList.SelectedItem;
string filePath = Path.Combine(@"d:\monitors.d\", fileName + ".yml");
if (File.Exists(filePath))
configReader.AppendText(File.ReadAllText(filePath));
else
configReader.Clear();
}
This is the part that I can't get to function properly
private void saveConfig_Click_1(object sender, EventArgs e)
{
string fileName = (string)configList.SelectedItem;
richTextBox1.AppendText(configReader.Text);
System.IO.File.WriteAllText(@fileName);
}
I can't figure out how to just save the change I want. The change I want to make is only this line in the config file:
docMeta.DownAcknowledge: False
And change that to
docMeta.DownAcknowledge: True
And vice versa. Then save the file exactly as is.