New Posts New Posts RSS Feed: Nullable DateTimePicker
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Nullable DateTimePicker

 Post Reply Post Reply
Author
Miszou View Drop Down
Newbie
Newbie
Avatar

Joined: 14-Jun-2007
Location: United States
Posts: 19
Post Options Post Options   Quote Miszou Quote  Post ReplyReply Direct Link To This Post Topic: Nullable DateTimePicker
    Posted: 16-Oct-2007 at 11:05am
I am trying to databind a nullable DateTime to the DateTimePicker in .NET.
 
However, it does not appear to be working as I would expect - and I'm not sure if this is due to the 3rd party DateTimePicker controls I am using, or whether the DateConverter is somehow translating the data prior to display.
 
I have tried several free controls that I have found on the internet, but none of them seem to work properly when binding to an EntityList<T>. I am particularly interested in using this one http://www.codeproject.com/cs/miscctrl/NullableDateTimePicker.asp as I like the display when there is no date. (a prompt string instead of an unchecked checkbox and todays date).
 
I realize that you probably aren't going to support this guys control (!), but I was wondering if you could perhaps point me in the right direction. I am wondering whether I have to create my own DataConverter to support null values? And if so, would you happen to have a DateConverter that supports null values just sort of lying around? Wink
 
Basically, do I need to write my own DevForce specific DateTimePicker and/or DateConverter to get it to work as I want?
 
Thanks for your help.
Back to Top
davidklitzke View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Posts: 715
Post Options Post Options   Quote davidklitzke Quote  Post ReplyReply Direct Link To This Post Posted: 16-Oct-2007 at 7:50pm

I am not entirely sure why you don't want to use the DevForce Nullable Date Picker.  I assume that you don't like the way it looks when the date is Null.

Here are some options:

(1) You might consider building a custom control based on the Nullable Date Picker.  Look at a previous post and the reply at:
 
http://www.ideablade.com/forum/forum_posts.asp?TID=133
 
It shows you how to create a custom control (a textbox with a blue background).  This custom TextBox will show up in the Designer and will be one of your choices for a TextBox control in your Autopopulate form.

I can give you the DataBinder for the NullableDataPicker.

(2) Use .NET databinding

You can use .NET databinding to bind to DevForce objects



Edited by davidklitzke - 16-Oct-2007 at 7:50pm
Back to Top
Miszou View Drop Down
Newbie
Newbie
Avatar

Joined: 14-Jun-2007
Location: United States
Posts: 19
Post Options Post Options   Quote Miszou Quote  Post ReplyReply Direct Link To This Post Posted: 17-Oct-2007 at 9:05am

Thanks for your quick reply.

Yes, the reason for using a different nullable date-time picker is due to a customer requirement that no date should be displayed if no date has yet been entered. The .NET date-time picker (is this the same as the DevForce one?) will always display a date, even when the value is null.
 
It has a strange checkbox implementation that is not intuitive at all - especially as null dates are displayed as todays date, but grayed out.
 
So, what I would really like, is a datetime picker that allows users to type freehand dates, but also contains a drop down picker. I was hoping to be able to use the control that I mentioned in my initial post, but I don't think it's going to work...
 
I think I am going to have to write my own control (using http://www.ideablade.com/forum/forum_posts.asp?TID=133 as a reference).
 
As far as I can see, there are a couple of ways to go about this. I can either create an owner-drawn date-time picker, or I can roll my own, using a combination of a combo-box and a calendar control, which is the direction I am leaning towards at the moment. I can catch the dropdown/up events and display the calendar appropriately and users can also type free text into the combo (which would of course be parsed by a DateConverter).
 
At some point, I will almost certainly need to host this control in a DataGridView as well, but I am assuming I can follow these instructions to implement that functionality: http://msdn2.microsoft.com/en-us/library/7tas5c80(VS.80).aspx 
 
You also mentioned that you could give me the DataBinder for the NullableDatePicker. If you could provide that, or even just an example of a custom DataBinder, I would be extremely grateful.
 
Thanks again for your response, and if you think of any additional hints or pitfalls to avoid, please let me know!
Back to Top
Customer View Drop Down
Senior Member
Senior Member
Avatar
User Submitted Questions to Support

Joined: 30-May-2007
Location: United States
Posts: 260
Post Options Post Options   Quote Customer Quote  Post ReplyReply Direct Link To This Post Posted: 17-Oct-2007 at 10:12am
See the post I last referenced (about the custom blue textbox control) to see an example of how to build a custom binder.
Back to Top
dr_kreso View Drop Down
Newbie
Newbie


Joined: 04-Jan-2010
Posts: 1
Post Options Post Options   Quote dr_kreso Quote  Post ReplyReply Direct Link To This Post Posted: 04-Jan-2010 at 12:39pm
1. Bind your datetimepicker.text, not datetimepicker.value
2. Add this code in datetimepicker_Validating(object sender, CancelEventArgs e) event:

if (!datetimepicker.Checked)
((Order)orderBindingSource.Current).OrderDate= null;

So, you need to manually set your Date to null value

3. ShowCheckBow of datetimepicker must be set to True

I hope it helps!
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down