NullableDateTimePicker for .NET 2.0-VBForums
Results 1 to 4 of 4

Thread: NullableDateTimePicker for .NET 2.0

Hybrid View

  1. #1

    Thread Starter
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    87,750

    NullableDateTimePicker for .NET 2.0

    In .NET 1.1 I used to use the ExtendedDateTimePicker control from the Quantum Software Solutions Windows Forms Components library. Unlike some of their other components, the ExtendedDateTimePicker is not compatible with .NET 2.0, so I have created a control that works similarly, although not exactly the same way.

    Features:
    • Control is blank (instead of showing greyed text) when ShowCheckBox is true and Checked is false.
    • DataValue property allows you to assign null values.
    • DataValueChanged event is raised only when the DataValue property value changes.


    DataValue property:
    The main advantage of the DataValue property is that it allows you to bind the control to a database field and simply uncheck the control to assign a null value to the database. It accepts DateTime objects to set the date/time or a null reference or DBNull.Value to clear it. When cleared, the property always returns DBNull.Value. Note that if ShowCheckBox is false then assigning a null value to the DataValue property has no immediate effect, i.e. the control still displays text and the DataValue property still returns a DateTime object. If ShowCheckBox becomes true however, the change then becomes apparent, i.e. the control is blank and the DataValue property returns DBNull.Value. This means basically that if the control is intended to be able to contain a null value then ShowCheckBox must be true.

    DataValueChanged event:
    The ValueChanged event of the DateTimePicker is raised at times when the Value property value hasn't actually changed. In contrast, the DataValueChanged event of this NullableDateTimePicker is only raised when the DataValue property value has changed. This will occur if the ShowCheckBox is true and the DataValue property value changes from null to a date/time or a date/time to null, or else when the DataValue property value changes from one data/time value to another.

    If you use this code and find any issues please post here.

    Note that the attached code was originally written in C# and was converted using Instant VB from Tangible Software Solutions.
    Attached Files Attached Files

    2007-2014

    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Pivot Control
    Beginner Tutorials: VB | C# | SQL

  2. #2
    New Member
    Join Date
    Jun 2008
    Posts
    1

    Re: NullableDateTimePicker for .NET 2.0

    This looks great - exactly what I need.
    I'm a bit of a beginner with VB .NET 2008.
    Ive copied your code into a class in my project but I'm not sure how to use the control in a form. I just drag an drop the datetimepicker from the datasource window. No doubt this is dead simple and I'm just being rather dim :-(

  3. #3

    Thread Starter
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    87,750

    Re: NullableDateTimePicker for .NET 2.0

    I'd actually suggest that you don't use this control. There's a bug in it that I didn't ever get around to fixing because QSS ended up releasing their WFC library for .NET 2.0. I'd suggest you follow that first link in the original post and get that.

    2007-2014

    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Pivot Control
    Beginner Tutorials: VB | C# | SQL

  4. #4
    Junior Member
    Join Date
    Nov 2010
    Posts
    30

    Re: NullableDateTimePicker for .NET 2.0

    Jm, any new solutions for the DTP? I'm having the same problem, I can null a date in the sql server with code and it saves fine, it's just the DTP control, when it runs over a null record it shows the value of the previous record, btw, the DTP works fine in a datarepeater for me with the checkbox but I want to get away from the datarepeater, thanks dotnet 3.5sp1

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.