The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

two way databinding issue with addnew

Last post 06-24-2008, 2:10 PM by driath. 4 replies.
Sort Posts: Previous Next
  •  06-24-2008, 11:56 AM 9975

    two way databinding issue with addnew

    This is all using the new ES 2008 released yesterday.


    I have a table which has six columns of type bit which do not allow nulls.
    The columns are databound to different CheckBox’s .Checked property via a BindingSource.


    The situation which breaks down is:
    When I add a new record, if don’t give one of the CheckBox focus at all, then the underlying property is still null and when I goto Save it will fail since we can’t put null in a non-null column.

    Was wondering if anyone has an elegant way of forcing an initial bind to make sure things like the state of checkboxes gets bound properly when a new item is added?

    Thanks,
    Jonathan

     

  •  06-24-2008, 12:13 PM 9976 in reply to 9975

    Re: two way databinding issue with addnew

    Well, it's my practice for "bit" fields to never allow null but make the default 0 or false. However, you could take this approach, in your "Custom" (not generated) class override AddNew() in our single entity class and set the bits to false? Not sure if that's what your after or not though. If you can change the database I would, unless you have a real reason for allowing bits to be null?
    EntitySpaces | Twitter | BLOG
  •  06-24-2008, 1:12 PM 9977 in reply to 9976

    Re: two way databinding issue with addnew

    Agreed.

     I will just set a default. The same issue happens with a textbox and a non-nullable varchar/char field. If i don't give it focus, it doesn't grab the fact that its an empty string unless I give the box focus and take it away.

    I do realize that in this trivial example you could just set the database field to null which would make more sense, but what if that's not an option. It seems tedious to have to manually set defaults, when the textbox properly holds string.empty normally, its just not getting passed back.
     

  •  06-24-2008, 1:55 PM 9978 in reply to 9977

    Re: two way databinding issue with addnew

    Are you using the standard windows controls or a 3rd party suite for the UI ?  Also, what do you mean by this:

    If i don't give it focus, it doesn't grab the fact that its an empty string unless I give the box focus and take it away.

    Are you saying you want "" back instead of the fields left as null?

     


    EntitySpaces | Twitter | BLOG
  •  06-24-2008, 2:10 PM 9979 in reply to 9978

    Re: two way databinding issue with addnew

    All standard windows controls.

    Yes, if the database column is not nullable, I wouldn't want a null when the .Text property already has "" sitting there.

    BTW, I don't think this is an ES issue after more prodding, its more that I'm stubborn and don't like it when databinding starts feeling counterintuitive to my personal needs. It does make sense that a control which never received focus should be considered NULL, unless the database column doesn't allow nulls which is when I want string.empty. I noticed this information is stored in the meta data so now I'll probably make an esBindingSource for winforms that will take advantage of as much of that meta data as possible to limit the amount of what I consider trivial coding.

     

View as RSS news feed in XML