C#, win App, Dialog in dialog, Dialogresult error | Newbie | | Join Date: Jul 2007
Posts: 11
| |
Hi there!
in my app, i open a Dialog, in this dialog i use the FileOpenDialog, when i click on 'Ok' or 'Cancel' in my FileOpenDialog, it automatically closes the parent dialog, with a DialogResult.Cancel???
I have overloaded the ShowDialog to accept parameters in the 'Parent' Dialog
main Code
...Calling Parent Dialog -
if (GenerelSetup.ShowDialog(ref szXStatIni, ref szLogbookFile) == DialogResult.OK)
-
{....}
-
Parent Dialog -
public DialogResult ShowDialog(ref string szStatIniFileName, ref string szMachinePath)
-
{
-
DialogResult ret;
-
this.szStatIniFileName = txtStatIni.Text = szStatIniFileName;
-
this.szMachinePath = txtMachinePath.Text = szMachinePath;
-
ret = this.ShowDialog();
-
return ret;
-
}
-
-
private void btnBrowseStatIni_Click(object sender, EventArgs e)
-
{
-
openFileDialog.Filter = "X-stat ini files (*.ini)|*.ini|All files (*.*)|*.*";
-
openFileDialog.FilterIndex = 1;
-
openFileDialog.FileName = "x-stat.ini";
-
openFileDialog.InitialDirectory = szStatIniFileName;
-
openFileDialog.RestoreDirectory = true;
-
-
if (openFileDialog.ShowDialog() == DialogResult.OK)
-
{
-
szStatIniFileName = openFileDialog.FileName;
-
txtStatIni.Text = openFileDialog.FileName;
-
}
-
}
-
The parent dialog opens correct, and the fileopen dialog opens as well.
Anybody able to give me a hint in the right direction??
|  | Moderator | | Join Date: Apr 2007 Location: New England
Posts: 7,161
| | | re: C#, win App, Dialog in dialog, Dialogresult error
On your parent dialog window, what buttons are set as the "ok" button and what is set as the "cancel" button?
Maybe it defaulted your button to be the cancel button?
| | Newbie | | Join Date: Jul 2007
Posts: 11
| | | re: C#, win App, Dialog in dialog, Dialogresult error
Hi Plater,
No, my 'Ok' button is defined as AcceptButton, and my Cancel button is defined as CancelButton on the parent dialog, but I dont touch any of these buttons, it automatically happens when i click on 'Ok' or 'Cancel' on the OpenFileDialog dialog...
|  | Moderator | | Join Date: Apr 2007 Location: New England
Posts: 7,161
| | | re: C#, win App, Dialog in dialog, Dialogresult error
Wierd. I just did it with no problem at all.
I had my mainwindow open another window with .ShowDialog() and inside that Dialog window I opened up an open file dialog.
No problems with it closing or anything.
Can you set a breakpoint in the button handler and step through the code, maybe that will help get an idea of what's going on?
| | Newbie | | Join Date: Jul 2007
Posts: 11
| | | re: C#, win App, Dialog in dialog, Dialogresult error
the parentdialog is activated by the statement ret = this.ShowDialog. in line 6
after pressing the buttonhandler, and accepting with an 'Ok' in the fileopendialog, it executes the correct code inside my buttonhandler and then continues to my 'Return ret' in line 7 and ret has the value of 'Cancel', forcing the parent dialog to close. -
public DialogResult ShowDialog(ref string szStatIniFileName, ref string szMachinePath)
-
{
-
DialogResult ret;
-
this.szStatIniFileName = txtStatIni.Text = szStatIniFileName;
-
this.szMachinePath = txtMachinePath.Text = szMachinePath;
-
ret = this.ShowDialog();
-
return ret;
-
}
-
Definately weird...
|  | Moderator | | Join Date: Apr 2007 Location: New England
Posts: 7,161
| | | re: C#, win App, Dialog in dialog, Dialogresult error
Maybe it has something to do with calling .ShowDialog() from inside itself, with your ShowDialog() Wrapper.
Would it not be better to do that with the constructor, or make some public properties that can be set with the values?
| | Newbie | | Join Date: Jul 2007
Posts: 11
| | | re: C#, win App, Dialog in dialog, Dialogresult error
No, tried to add it to the constructor, but same error.
Then i inspected the .Designer.cs .
It seems somehow Cancel had been added to all my buttons,even the button for showing the FileOpenDialog, althoug looking correct in the properties pane...
Removing these, and adding: -
this.btnOk.DialogResult = System.Windows.Forms.DialogResult.OK;
-
.
-
.
-
this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
-
It now works perfect.
Thanks for your time Plater, take care.
| | Newbie | | Join Date: Sep 2008
Posts: 1
| | | re: C#, win App, Dialog in dialog, Dialogresult error
This usually happens when one copies a button with the Dailog Result set. It is easy to do this when designing a wizard for instance and one uses the ok or cancel button as a template button that is placed somewhere else.
|  | Similar .NET Framework bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,418 network members.
|