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 3426374
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:42:29+00:00 2026-05-18T06:42:29+00:00

I have a winforms checkbox that is bound to a property of an Entity

  • 0

I have a winforms checkbox that is bound to a property of an Entity Framework entity.

So for example, I have bindingSource.DataSource = myDog with a checkbox bound to the property IsSleeping, so that when the user checks the box, IsSleeping becomes true, and when the user unchecks the box, IsSleeping becomes false.

This works fine. The problem is that the value of IsSleeping is not updated until the checkbox is validated, which only occurs when focus moves away from the checkbox to something else. Thus, if I want something to happen when the box is unchecked:

private void IsSleepingCheckbox_CheckedChanged(object sender, EventArgs e)
{
    OnDogPropertyChanged(myDog);
    MyAnimalEntities.SaveChanges();
}

myDog.IsSleeping will still be true, until the checkbox’s Validated is later raised. Thus, when poor myNaughtyKitty (who is listening to the DogPropertyChanged event) comes to eat out of myDog‘s food dish thinking myDog is sleeping, myDog is really just waking up! Oh no!

Even worse, MyAnimalEntities.SaveChanges() does not see the changes to myDog yet, so the value of IsSleeping is never saved to the database. Moving the .SaveChanges() call to IsSleepingCheckbox_Validated does not solve this problem, because if the checkbox is toggled but then the form is closed without ever moving focus away from the checkbox, the checkbox is never validated and thus its state is never saved!

I imagine this must be a fairly common problem with databinding and checkboxes/textboxes, and indeed I’ve found a ton of posts on the subject online, but no one ever seems to have a solution. Has anyone been able to find a workaround for this?

  • 1 1 Answer
  • 0 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-18T06:42:29+00:00Added an answer on May 18, 2026 at 6:42 am

    You can change the Binding.DataSourceUpdateMode property to OnPropertyChanged (the default is OnValidation), which will cause the data source to be updated when the user clicks the checkbox. Unfortunately, the CheckedChanged event still fires before the data source is updated.

    To deal with this, you can handle the BindingSource.ListChanged event and move your SaveChanges code there.

    bindingSource = new BindingSource();
    bindingSource.DataSource = myDog;
    checkBox1.DataBindings.Add(new Binding("Checked", bindingSource, "IsSleeping"));
    checkBox1.DataBindings[0].DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;
    
    bindingSource.ListChanged += new ListChangedEventHandler(bindingSource_ListChanged);
    

    HTH

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

Sidebar

Related Questions

I have a have Winforms client that uses Web services on a IIS7 (W2008)
I have a Winforms application (written in C#) that is deployed on a network
I have a winforms app that initially displays a window with two file dialog
I have a winforms application and I am trying to create a method that
I have a winforms Application, On Close button click, I am hiding that application
I have a winforms c# app that has an embedded webbrowser control inside it
WinForms have those three boxes in the upper right hand corner that minimize, maximize,
Winforms .net 3.5 app. In my app I have a generic class that looks
I have a winforms application that has one tabcontrol with 2 pages. On both
I have a Winforms application that uploads images to SQL Server 2005 as Image

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.