This still did not help. The dialog do not uppdate and show the path that I
set in my event handler for the OK button.
> > > > I want to change the current path in the OpenFileDialog in runtime. When the
> > > > user presses OK-button I'm checking the selected path if it's valid for my
[quoted text clipped - 18 lines]
>
> by default both are set to true;
> This still did not help. The dialog do not uppdate and show the path that I
> > > > > I want to change the current path in the OpenFileDialog in runtime. When the
[quoted text clipped - 19 lines]
>
> > by default both are set to true;
With the change I suggested, when user press ok button, even if the
file or directory is bad, it should close the fie dialog and you have
to validate the data yourself and if the data is bad show the file
dialog again.
My question, when you press the open button, did the window close or
did it show the error again?
If you have the code, please send it and let me have a look.
Thanks.
Per - 02 Apr 2008 16:06 GMT
This is not an option to close the dialog and then open it again.
Here is a code snippet of what I want to do.
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
string fileName = "";
dlg.FileName = "";
dlg.Title = "Test";
dlg.InitialDirectory = "C:\\Temp";
dlg.CheckFileExists = true;
dlg.CheckPathExists = true;
// Setup event to validate if it's ok to proceed with open
command.
dlg.FileOk += new CancelEventHandler(OnFileOk);
if(dlg.ShowDialog() == DialogResult.OK)
{
fileName = dlg.FileName;
}
}
void OnFileOk(object sender, CancelEventArgs e)
{
OpenFileDialog dlg = sender as OpenFileDialog;
string path = Path.GetDirectoryName(dlg.FileName);
if (path.ToLower() != dlg.InitialDirectory.ToLower())
{
// Not a valid path.
// Here I want to set the dialog to show the
InitalDirectory.
// I want the dialog to show the files under C:\Temp not the
files in
// the right now selected directory that is not valid.
// The Open command is canceled
e.Cancel = true;
}
else
{
// This is a valid path.
// Proceed with the Open command.
e.Cancel = false;
}
}
> > This still did not help. The dialog do not uppdate and show the path that I
> > > > > > I want to change the current path in the OpenFileDialog in runtime.. When the
[quoted text clipped - 29 lines]
> If you have the code, please send it and let me have a look.
> Thanks.
CSharper - 02 Apr 2008 16:21 GMT
> This is not an option to close the dialog and then open it again.
>
[quoted text clipped - 80 lines]
> > If you have the code, please send it and let me have a look.
> > Thanks
Based on my limited knowledge I think it is not possible with
FileDialog if you do not want to close and open, may be you can create
a custom filedialog inherit from filedialog and in there, overwrite
the open method to handle this situation..