Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 963875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:44:19+00:00 2026-05-16T01:44:19+00:00

This is a winform C# problem. I have an data object, say, Person. It

  • 0

This is a winform C# problem.

I have an data object, say, Person. It has a property called Age and if Age is set to a negative value an exception will be thrown from its property setter.

On the form, the Age property is bound to a textbox using:

var binding = tbAge.DataBindings.Add("Text", person, "Age", true, DataSourceUpdateMode.OnValidation);

In order to discover the error, I create an BindingComplete event listener and test the BindingCompleteState against BindingCompleteState.Success and show necessary error message to the user.

That is all the background. Now, if I set a negative value on the textbox and DIRECTLY click the X button on the right top of the form to close it, the expected error message shows but the form is not closed.

I want the form to be closed and don’t care if the error message is shown or not in this case. The validation part is preferred not to be altered. I don’t want to hide the X button and put a close button on the form manually. Is there any right way to achieve my purpose? Thank you very much for any help.

  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T01:44:20+00:00Added an answer on May 16, 2026 at 1:44 am

    I just found a solution.

    Though I still remain unknown the reason why the form is prevented from closing, I guess it has something to do with the exception I throw from the data object and some validation of the form. (Please correct me if I am wrong.)

    Disable AutoValidate of the form is not a solution. Since then my error message will not be shown.

    What I do is implement the IDataErrorInfo for the Person class. Normally the textbook tells that IDataErrorInfo works with some ErrorProvider UI component to show the red circle next to the control. We don’t use ErrorProvider at all. But IDataErrorInfo is still useful because the BindingCompleteState will still be set to proper status. So IDataErrorInfo acts as a bridge between my data object and the bindingsource, to pass underlying data level errors to surface. Then the bindingcomplete event does the same thing.

    The key of using IDataErrorInfo is now I can close my form without any problem. I still don’t know why but without the exception being thrown from data object, the form can close itself properly. Let me know what is the reason to prevent the form from closing in my problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first winform app in .NET... I have made a couple of
this can be asked with webform or winform... i have a .net program (exe)
I have an application (winform exe) that I run several times. Does this mean
I have a datagridview in a C# Winform project. This datagridview is used to
I have a Winform DataGridView , which has a number of predefined columns. Now
I have this problem, I wrote a WinForms application, I have use it for
I have a problem: change setting in user control's configuration file has no effect.
Explanation: Let's say I have an object graph that's nested several levels deep and
I have a problem with binding data using BindingSource, typed dataset and DataGridView. My
I have a winform with a form called MainForm. I have a static class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.