user896692
user896692

Reputation: 2371

showDialog() shows result without call

I´ve got the following code-line to show a Window in a MessageBox:

MessageBox.Show(new ElbaKostenstellen(titel, loginid).ShowDialog().ToString());

The problem is, that when I close it, another MessageBox starts with true or false, but I never told it to do. How can I fix that?

Here´s more relevant code:

                    string ganzes = sr.ReadToEnd();
                    string[] allezeilen = ganzes.Split('\n');

                    for (int i = 0; i < allezeilen.Length - 1; i++)
                    {
                        string[] separated = allezeilen[i].Split(';');

                        String datum = separated[0];
                        String titel = separated[1];
                        if (titel.Contains('"'))
                        {
                            titel = titel.Replace('"', ' ');
                        }
                        String betrag = separated[3];
                        buchrep.bookFromElbaCSV(datum, titel, betrag, loginid);
                        //ElbaKostenstellen ek = new ElbaKostenstellen(titel, loginid);
                        //ek.Show();
                       MessageBox.Show(new ElbaKostenstellen(titel, loginid).ShowDialog().ToString());
                    }

Upvotes: 0

Views: 280

Answers (4)

MaLio
MaLio

Reputation: 2530

lets look at

MessageBox.Show(new ElbaKostenstellen(titel, loginid).ShowDialog().ToString()); 

The first bit that gets evaluated is

new ElbaKostenstellen(titel, loginid).ShowDialog()

this shows the dialog and the execution of code is blocked until the dialog is closed.

then the

MessageBox.Show(...)

is executed and displays the string representation of the result of the previous dialog.

I suspect you do not need the MessageBox.Show(..), just the new ElbaKostenstellen(titel, loginid).ShowDialog()

Upvotes: 1

Likurg
Likurg

Reputation: 2760

You told it when write this string

MessageBox.Show(new ElbaKostenstellen(titel, loginid).ShowDialog().ToString());

So you need to get message from ElbaKostenstellen without calling ShowDialog()

Upvotes: 1

Dor Cohen
Dor Cohen

Reputation: 17080

This is because the return value of ShowDialog is true or false.

As written here - http://msdn.microsoft.com/en-us/library/system.windows.window.showdialog.aspx

Return Value

Type: System.Nullable A Nullable value of type Boolean that specifies whether the activity was accepted (true) or canceled (false). The return value is the value of the DialogResult property before a window closes.

Upvotes: 0

tafa
tafa

Reputation: 7316

In order to show a form calling ShowDialog on it is enough, a call to MessageBox.Show is unnecessary. Try;

new ElbaKostenstellen(titel, loginid).ShowDialog();

instead of

MessageBox.Show(new ElbaKostenstellen(titel, loginid).ShowDialog().ToString());

Upvotes: 4

Related Questions