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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:11:42+00:00 2026-05-16T20:11:42+00:00

I haven’t really done a two way binding project before, so this might be

  • 0

I haven’t really done a two way binding project before, so this might be a simple question.

I have an business object with all the right interfaces (INotifyPropertyChanged, etc…). I bound a Int32 property called CPP to a textbox named txtCPP via a BindingSource. The rules state that if CPP is less than 0, the text box should be blank, otherwise should display a value.

So to make that happen, I changed the property from Int32 to Int32? (nullable) and when the backing variable of the CPP property is less than zero, I actually return null.

This actually works fine with the UI. The problem comes when I want to persist the business object to the database. An external method takes the business object, reads its properties (including CPP) and persists them to the database. And obviously, instead of CPP being -1, it is being written as null.

I am sure I am not the first person to come up with this issue when doing two-way binding projects. How does one typically handle these problems in a clean way without polluting the form code with edge cases like that?

  • 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-16T20:11:43+00:00Added an answer on May 16, 2026 at 8:11 pm

    It sounds as though your rule about the box being blank is a UI rule, and not a data rule (so the data value really is -1, it just should be displayed as blank).

    If that’s the case, lets move the blank logic into the UI. So, your data object property returns an int (and it returns the real value of the int), and then you can morph it in your display.

    One way to do that would be with formatting — you can specify a Formatter with your databinding, or you can hook the Format event on the databinding.

    Of course, you still need to decide what to do when the user enters a blank value into the textbox…

    Here’s a really simple-minded example, using the Format event in the databinding:

    
    var binding = this.textBox1.DataBindings.Add("Text", MyObject, "AValue", true);
    binding.Format += (s, args) =>
        {
            int i = (int)args.Value;
            if (i <= 0)
            args.Value = "";
        };
    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I haven't really done much on this side of project development so please forgive
Haven't seen many Geneva related questions yet, I have posted this question in the
I haven't seen this datetime format before: 2010-08-19T16:09:07.08 The nearest I have found in
Haven't done ASP.NET development since VS 2003, so I'd like to save some time
I haven't done a lot of .NET programming, but I've examined a few of
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
Haven't seen this feature anywhere else. I know that the 32nd bit is used
I haven't been able to find a very good way of getting 10 random
I haven't deployed the application yet. I'm new to this, how can i create

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.