473,800 Members | 2,648 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

11 New Member
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.Ca ncel???

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 5590
Plater
7,872 Recognized Expert Expert
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
Masterfrier
11 New Member
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 Recognized Expert Expert
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
Masterfrier
11 New Member
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 Recognized Expert Expert
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
Masterfrier
11 New Member
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
FlawedBlake
1 New Member
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
16262
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 Server might not be running or the path exists and is redirected to another machine. Please check the status of this virtual directory in the Internet Services Manager."
4
3522
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 Fixpack on a test machine running ESE but encountered a serious error during the install. It started 'copying new files' but then stopped cold and displayed a dialog box asking me to "Please insert disk 1". (It all fit on one CD!) I clicked OK...
5
3701
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
3841
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 properties. I have added a new windows form, class 'DogProperties'. I'm attempting to use this to allow the user to edit the properties of an instance of 'Dog'.
2
1531
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 value. Tx Nick
4
6812
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 specific error occured: 0." How do I (if it is possible) change the value of the zero to something custom (like a "look in the event log for further information" message)? Thank you,
1
1242
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:\" CommonDialog1.ShowSave __________________ Cancel: End Sub
3
2954
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 this, In the dialog box the error which i specified here occurs. Could not open port 3306 for mysql server. Open the port 3306 in your firewall. Options occur in the dialog box are try and skip. I am using mcafee firewall and i have opened...
3
4949
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() { $("#dialog").dialog("destroy"); $("#dialog-form").dialog({
0
10501
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10250
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10032
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7574
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5469
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5603
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2944
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.