The v2 DatePicker doesn't support null databinding (bug?)

The following code (which is a simple test windows form - visual studio team 2005 system beta 3 refresh) demonstrates what I believe is a bug in the DatePicker control.

When a datepicker is bound to a binding source set to an object, properties of type DateTime that are null are not updated when the user (at runtime) changes the date.

This is a real pain; and, frankly, makes the date picker useless to bind to database-derived datatables which could contain dbnull.

Thank you in advance for your help.

(also: why is it called datetime picker when it does not pick the time )


Answer this question

The v2 DatePicker doesn't support null databinding (bug?)

  • Crane101

    That's life!

  • patspam

    That approach is probably the more common one I've seen -- you use your own text box and just the drop-down portion of the DatetimePicker. You might be able to find some code for this (at least some starting code) at www.codeproject.com.

    -mark
    Program Manager
    Microsoft
    This post is provided "as-is"


  • Todd Biggs - MSN Product Manager

    Correct. The DateTime picker does not support null DateTime values.

    -mark
    Program Manager
    Microsoft
    This post is provided "as-is"


  • Alejandro F.

    What influences the prioritization of changes to windows form controls Other than non-functional, how can not-as-functional be esclated Request from a big client Bad press What drives that sort of decision making process There's nots of traffic in newsgroups on this very topic from as far back as VB6. Or, honestly, is Microsoft general approach to rely heavily on third party control vendors

    Thank you.



  • Daniel Mart&#237&#59;n

    The DateTimePicker like other ComCtl controls is just something that we wrap and it was hard or impossible to get changes done to this without recreating the control from scratch. Because of this and because we had time and resource constraints, we were not able to address these changes in this version.

    -mark
    Program Manager
    Microsoft
    This post is provided "as-is"


  • Brian Lowe

    I'd recommend a third-party calendar/date picker control if you need to support null DateTime values. I haven't yet seen one that does, but there should be some soon. In the mean time, you might be able to handle the formatting/parsing yourself by handling the Format and Parse events on the data binding. This will allow you the chance to query to see if the value is a null DateTime and if so perform some action with the datetime picker.

    -mark
    Program Manager
    Microsoft
    This post is provided "as-is"


  • xurfie

    To me, not including support for date null values shows that Microsoft has a lot to learn, and that their focus is totally wrong! It's probably the first thing you would look for in such a control so that they have managed to overlook this feature makes you think what other things they have overlooked. Maybe they've been consentrating all their efforts on making the DataGridView almost useless because of all the different settings it's got, but really this is no excuse unless you are a comedian.

    To me, coming from the world of MS Access it seems like the .NET people don't talk to the MS Access people at all in Microsoft. MS Access is almost perfect when it comes to handling data while .NET is pathetic and hopeless. And then I'm basically just talking about the controls. Yes, Visual Studio is much more than a database front end builder but that sort of statement doesn't really help me or millions of others trying to build database front end applicaitons. It should be easy. It's not. Nor are there any sort of professional examples anywhere. Why


  • James Newman

    That null support is a bummer... :)

    What I did for another an inherited textbox, not the Datetimepicker, was this, I guess you can use the same approach.

    Bind to the BindableValue property that you create, not to the Value or the Text property...

    Hope it helps...

    public class CurrencyEditor : TextBox
    {
    // some other code here for supporting different currencies, such as the _Formatter

    public decimal Value
    {
    get
    {
    if (Text == "")
    {
    return 0;
    }
    try
    {
    return decimal.Parse(Text, NumberStyles.Currency, _Formatter); ;
    }
    catch
    {
    Value = 0;
    return 0;
    }
    }
    set
    {
    Text = value.ToString("C", _Formatter);
    }
    }

    [System.ComponentModel.Bindable(true)]
    public object BindableValue
    {
    get
    {
    if (Text == "")
    {
    return null;
    }
    else
    {
    return decimal.Parse(Text, NumberStyles.Currency, _Formatter); ;
    }
    }
    set
    {
    try
    {
    if (value == null)
    {
    Text = "";
    }
    else
    {
    Value = decimal.Parse (value.ToString());
    }
    }
    catch
    {
    Text = "";
    }
    }
    }

    }

    PS: I had to display different currencies on the same form (talk about the same grid OMG...), maybe that should be a candidate for next LOB controls...

    PSPS: I root for infragistics on the grid... Now with Vusual Inheritance omitted, their XML layouts might be the only option I am left with...



  • Adiavn

    With all due respect, shame on the team for making a data bound control with such a fatal flaw in an old version of the framework and not fixing it in the new version. Especially when the fix is so simple; we have our inherited wrapper complete now (solving the problem with the new custom control) a whole day after we started. How long would it have taken you guys to do it better

    Seems shameful, but maybe there's more to it than meets the eye..

     



  • Antonello Bianchi

    Your next set of LOB controls

    Can you tell me more :)



  • ItsMe!!!

    Customer feedback drives prioritizations more than anything. Filing a bug report and having multiple people vote on it is the best thing to raise awareness of the issues. Believe me though, calendar issues in general rates very high for doing in our next set of LOB (line of business) controls. I can't make promises though.

    -mark

    Program Manager

    Microsoft

    This post is provided "as-is"


  • SirusSoftsInc.

    Okay, thanks; it's nice to be correct - but honestly what I was really looking for was a way to bind a date from the database to a winform; a workaround or something - throw me a bone here. Please.



  • Pork

    Okay. I was hoping third party wasn't the answer, but I appreciate your straight forwardness.

    Our team today, assuming it was a brick wall of a problem, started writing an extended date picker that inherited the out-of-the-box but overloaded the Text property. Seems like it's a reasonable solution.

    You have not seen that done before or know of some sample for guidance do you



  • Kushan

    First off we would have had to deal with potential breaking changes, so we might have had to create a new control. Second, calendar needs stretch way outside a "standard" calendar format as some countries have their own calendar format and system, so there has to be a lot of logic there. In addition, even the names of days and months has to support being localized and the layout supporting these types of changes. The layout also needs to support right to left as well and accessibility issues.

    So, assuming that we had to recreate the control, my personal estimation would be a month spec/design effort followed by a month dev effort, followed by a month and a half test effort.

    -mark
    Program Manager
    Microsoft
    This post is provided "as-is"


  • The v2 DatePicker doesn't support null databinding (bug?)