473,387 Members | 3,787 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

C#, win App, Dialog in dialog, Dialogresult error

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
Expand|Select|Wrap|Line Numbers
  1. if (GenerelSetup.ShowDialog(ref szXStatIni, ref szLogbookFile) == DialogResult.OK)
  2. {....}
  3.  
Parent Dialog
Expand|Select|Wrap|Line Numbers
  1.         public DialogResult ShowDialog(ref string szStatIniFileName, ref string szMachinePath)
  2.         {
  3.             DialogResult ret;
  4.             this.szStatIniFileName = txtStatIni.Text = szStatIniFileName;
  5.             this.szMachinePath = txtMachinePath.Text = szMachinePath;
  6.             ret = this.ShowDialog();
  7.             return ret;
  8.         }
  9.  
  10.         private void btnBrowseStatIni_Click(object sender, EventArgs e)
  11.         {
  12.             openFileDialog.Filter = "X-stat ini files (*.ini)|*.ini|All files (*.*)|*.*";
  13.             openFileDialog.FilterIndex = 1;
  14.             openFileDialog.FileName = "x-stat.ini";
  15.             openFileDialog.InitialDirectory = szStatIniFileName;
  16.             openFileDialog.RestoreDirectory = true;
  17.  
  18.             if (openFileDialog.ShowDialog() == DialogResult.OK)
  19.             {
  20.                 szStatIniFileName = openFileDialog.FileName;
  21.                 txtStatIni.Text = openFileDialog.FileName;
  22.             }
  23.         }
  24.  
The parent dialog opens correct, and the fileopen dialog opens as well.

Anybody able to give me a hint in the right direction??
Oct 10 '07 #1
7 5569
Plater
7,872 Expert 4TB
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?
Oct 10 '07 #2
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...
Oct 10 '07 #3
Plater
7,872 Expert 4TB
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?
Oct 10 '07 #4
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.

Expand|Select|Wrap|Line Numbers
  1.         public DialogResult ShowDialog(ref string szStatIniFileName, ref string szMachinePath)
  2.         {
  3.             DialogResult ret;
  4.             this.szStatIniFileName = txtStatIni.Text = szStatIniFileName;
  5.             this.szMachinePath = txtMachinePath.Text = szMachinePath;
  6.             ret = this.ShowDialog();
  7.             return ret;
  8.         }
  9.  
Definately weird...
Oct 10 '07 #5
Plater
7,872 Expert 4TB
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?
Oct 10 '07 #6
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:
Expand|Select|Wrap|Line Numbers
  1. this.btnOk.DialogResult = System.Windows.Forms.DialogResult.OK;
  2. .
  3. .
  4. this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  5.  
It now works perfect.

Thanks for your time Plater, take care.
Oct 10 '07 #7
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.
Sep 8 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Tony Wright | last post by:
Hi, I am having a problem installing an msi for a web site. The error message I am getting is: "The specified path 'http://mipdev05/features/Fas2' is unavailable. The Internet Information...
4
by: pshindle | last post by:
DB2 Team - I just downloaded and unzipped the new Fixpack 9 for DB2 ESE V8 for Windows (FP9_WR21350_ESE.exe). I then burned the unzipped Fixpack files to a CD. I proceded to install this...
5
by: Daniel | last post by:
what do you have to do in a C# dialog so that it returns to ShowDialog as DialogResult.OK ?
6
by: bryanhobson | last post by:
I'm fairly new to c#, and I am just trying to work out how a 'properties' dialog works. Currently in my code, I have an object represented by the class 'Dog'. The dog object has several...
2
by: Angel Soft | last post by:
sorry, I have a stupid question I open a form with ShowDialog because I need a value from this form. how do I set the result value of this "dialog" form? DialogResult property do not accept any...
4
by: Jason Richmeier | last post by:
I am sure this has been asked at least once before but I could not find anything when searching. If I set the value of the ExitCode property to 1066 for a windows service, the text "A service...
1
by: vishalgupta | last post by:
i have a defined a function which i when call displays the saveas dialog box. i have used the following code: Private Sub ClT() On Error GoTo Cancel CommonDialog1.InitDir = "C:\"...
3
by: Ananthu | last post by:
Hi I have downloaded mysql server 5.0.45 for windows and when i try to install all the steps i followed the installation process but at the last stage that is configuration stage i get error like...
3
pradeepjain
by: pradeepjain | last post by:
hii.. i use cope like this <td><a href='/login.php' id="view-user" >Pradeep</a></td> and defauly jquery dialog code <script type="text/javascript"> $(function() {...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.