G
Guest
Hi everybody,
this is my first post to this newsgroup.
I have a problem with OpenFileDialog. I programmed a windows form that has a
button that opens a OpenFileDialog. If a user chooses a file and presses the
OpenFileDialogs "Open" button, the chosen file will be added to a list box.
If the user presses the "Save and Close" button of my form the content of the
list box will be written to an xml file.
Here is my code that adds the filename to the list box:
private void addFileButton_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = "Add Programs to supervise";
if (ofd.ShowDialog() == DialogResult.OK)
{
Log.Write("Adding " + ofd.FileName);
supervisedFilesListBox.Items.Add(ofd.FileName);
}
}
Unfortunately this does not work! The file name is added to the list box.
But - if my "Save and Close" button is clicked the form is closed but nothing
else happens.
If I replace the addFileButton_Click method by this one:
private void addFileButton_Click(object sender, EventArgs e)
{
supervisedFilesListBox.Items.Add(@"C:\autoexec.bat");
}
everything works fine. "C:\autoexec.bat" is added to the list box every time
I click the addFileButton and if I click the "Save and Close" button the xml
file is correctly generated.
I would be very glad if someone could tell me what I'm doing wrong!
Thanks in advance,
Sascha
this is my first post to this newsgroup.
I have a problem with OpenFileDialog. I programmed a windows form that has a
button that opens a OpenFileDialog. If a user chooses a file and presses the
OpenFileDialogs "Open" button, the chosen file will be added to a list box.
If the user presses the "Save and Close" button of my form the content of the
list box will be written to an xml file.
Here is my code that adds the filename to the list box:
private void addFileButton_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = "Add Programs to supervise";
if (ofd.ShowDialog() == DialogResult.OK)
{
Log.Write("Adding " + ofd.FileName);
supervisedFilesListBox.Items.Add(ofd.FileName);
}
}
Unfortunately this does not work! The file name is added to the list box.
But - if my "Save and Close" button is clicked the form is closed but nothing
else happens.
If I replace the addFileButton_Click method by this one:
private void addFileButton_Click(object sender, EventArgs e)
{
supervisedFilesListBox.Items.Add(@"C:\autoexec.bat");
}
everything works fine. "C:\autoexec.bat" is added to the list box every time
I click the addFileButton and if I click the "Save and Close" button the xml
file is correctly generated.
I would be very glad if someone could tell me what I'm doing wrong!
Thanks in advance,
Sascha