Canceling a forms OK button

Stimulsoft Reports.NET discussion
mmurdock
Posts: 94
Joined: Tue Mar 20, 2007 4:59 pm

Canceling a forms OK button

Post by mmurdock »

So when a user presses an OK button on a report form whose dialog default is set to "OK" I would like it to check to make sure that all of the form data is filled in before running the report. If it is not then pop up a message and cancel running the report. I have been able to code my form to check the fields and pop up a message box, but I do not know how to cancel running the report. Any help would be appreciated.

Thanks,

Mat
Vital
Posts: 1278
Joined: Fri Jun 09, 2006 4:04 am

Canceling a forms OK button

Post by Vital »

Set property DialogResult to None. After then use following code:

Code: Select all

if (condition)Form1.Close();
else ......
Thank you.
Jennypi
Posts: 361
Joined: Mon Nov 17, 2008 7:13 am
Location: France

Re: Canceling a forms OK button

Post by Jennypi »

Hello,

I'm having the same request. Thanks to this topic, I've managed to write this code:

Code: Select all

if (TextBoxControl1.Control.Text=="")
{MessageBox.Show("Please enter the first sample number");}
else
{
labels.Connect();
Traits.Connect();
Form1.Close();
}
if everything is OK, the form should be closed and the report should run. With this code, the form is well closed, but the report is blank. Do I miss something in my code to render the report?

Thank you.
Jennypi
Posts: 361
Joined: Mon Nov 17, 2008 7:13 am
Location: France

Re: Canceling a forms OK button

Post by Jennypi »

Hello,

Any idea to answer my question?

Thanks :)
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Canceling a forms OK button

Post by Alex K. »

Hello,

Can you please send us a sample report with test data which reproduce the issue for analysis.

Thank you.
Jennypi
Posts: 361
Joined: Mon Nov 17, 2008 7:13 am
Location: France

Re: Canceling a forms OK button

Post by Jennypi »

Sure.
I'm joigning the original report, which is working:
excel source OK.mrt
(38.97 KiB) Downloaded 339 times
and the modified report which is not working:
excel source KO.mrt
(39.02 KiB) Downloaded 408 times
and the data file:
Data2.xlsx
(79.32 KiB) Downloaded 368 times
The modified report asks that the user must enter something in the form.

Thank you.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Canceling a forms OK button

Post by Alex K. »

Hello,

In this case you close form without render report and get the blank page.Please try to set the DialogResult property for the "Ok" button as Ok,

Thank you.
Jennypi
Posts: 361
Joined: Mon Nov 17, 2008 7:13 am
Location: France

Re: Canceling a forms OK button

Post by Jennypi »

Thank you for your reply.
I tried this. But when there is an empty string in the TextBox, the message is well displayed to the user, but the report is rendered (and showing an error message "Input string was not in a correct format."), instead of showing again the form so that the user can type something.
Look at the modified report:
excel source KO.mrt
(39.06 KiB) Downloaded 311 times
Thanks.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Canceling a forms OK button

Post by Alex K. »

Hello,

Please try to use the following code:

Code: Select all

if (TextBoxControl1.Control.Text=="")
{
   MessageBox.Show("Please enter the first sample number");
   this.IsStopped = true;
}
else
{
   labels.Connect();
   Form1.Close();
}
Thank you.
Jennypi
Posts: 361
Joined: Mon Nov 17, 2008 7:13 am
Location: France

Re: Canceling a forms OK button

Post by Jennypi »

Thanks but it's not working. The code "this.IsStopped = true;" doesn't stop the report rendering.

Any other idea? :)
Thank you.
Post Reply