PC Review Forums Newsgroups Microsoft DotNet Microsoft ADO .NET Binding DateTimePicker

Reply

Binding DateTimePicker

 
Thread Tools Rate Thread
Old 27-12-2006, 10:06 AM   #1
=?Utf-8?B?Sm9obiBTdGl2ZW5zb24=?=
Guest
 
Posts: n/a
Default Binding DateTimePicker


A DateTimePicker control on my form is bound to a datetime field in a
DataTable.
When inserting a new record the default value for DateTimePicker is today's
date.
However, unless the user changes this date it is not saved to database (NULL
is stored instead of today's date). Text fields are stored normally.

A TextBox control has similar behavior: if the user leaves
a text box blank, NULL is sent to database, but if he enters
some text and then deletes it, an empty string is stored.
It seems that there is some "Modified" property for every control.

In this case I want to store the current date instead of NULL.
How can I achive this?

  Reply With Quote
Old 27-12-2006, 11:11 AM   #2
Cor Ligthert [MVP]
Guest
 
Posts: n/a
Default Re: Binding DateTimePicker

John,

What have you binded because as this question comes the reason is mostly
that there is binded to the text property from the datetime picker. That has
to the value property, normally this should go fluently.

Cor

"John Stivenson" <JohnStivenson@discussions.microsoft.com> schreef in
bericht news:A8617AA3-F6BD-4E37-A34C-5C73633CFB04@microsoft.com...
>A DateTimePicker control on my form is bound to a datetime field in a
> DataTable.
> When inserting a new record the default value for DateTimePicker is
> today's
> date.
> However, unless the user changes this date it is not saved to database
> (NULL
> is stored instead of today's date). Text fields are stored normally.
>
> A TextBox control has similar behavior: if the user leaves
> a text box blank, NULL is sent to database, but if he enters
> some text and then deletes it, an empty string is stored.
> It seems that there is some "Modified" property for every control.
>
> In this case I want to store the current date instead of NULL.
> How can I achive this?
>



  Reply With Quote
Old 28-12-2006, 12:06 PM   #3
Bart Mermuys
Guest
 
Posts: n/a
Default Re: Binding DateTimePicker

Hi,

"John Stivenson" <JohnStivenson@discussions.microsoft.com> wrote in message
news:A8617AA3-F6BD-4E37-A34C-5C73633CFB04@microsoft.com...
>A DateTimePicker control on my form is bound to a datetime field in a
> DataTable.
> When inserting a new record the default value for DateTimePicker is
> today's
> date.
> However, unless the user changes this date it is not saved to database
> (NULL
> is stored instead of today's date). Text fields are stored normally.
>
> A TextBox control has similar behavior: if the user leaves
> a text box blank, NULL is sent to database, but if he enters
> some text and then deletes it, an empty string is stored.
> It seems that there is some "Modified" property for every control.


That right, well it's the Binding that has a (private) modified flag which
is triggered by the Control property-Changed event (eg.
TextChanged/ValueChanged). The value isn't persisted if the modified flag
hasn't been set.

>
> In this case I want to store the current date instead of NULL.
> How can I achive this?


Try to set default values on the DataSource.

If you're using NET2.0 you can use the DataTable.TableNewRow event.

HTH,
Greetings




>



  Reply With Quote
Old 30-12-2006, 09:42 PM   #4
=?Utf-8?B?Sm9obiBTdGl2ZW5zb24=?=
Guest
 
Posts: n/a
Default Re: Binding DateTimePicker

"Bart Mermuys" wrote:

> > In this case I want to store the current date instead of NULL.
> > How can I achive this?

>
> Try to set default values on the DataSource.
>
> If you're using NET2.0 you can use the DataTable.TableNewRow event.


It seems as a good solution, but I don't know how to do this.
Where should I add TableNewRow event handler?

Thanks in advance.
  Reply With Quote
Old 31-12-2006, 08:05 AM   #5
Bart Mermuys
Guest
 
Posts: n/a
Default Re: Binding DateTimePicker

Hi,

"John Stivenson" <JohnStivenson@discussions.microsoft.com> wrote in message
news:9D50C122-47ED-4466-A8A0-4C311FCDBD43@microsoft.com...
> "Bart Mermuys" wrote:
>
>> > In this case I want to store the current date instead of NULL.
>> > How can I achive this?

>>
>> Try to set default values on the DataSource.
>>
>> If you're using NET2.0 you can use the DataTable.TableNewRow event.

>
> It seems as a good solution, but I don't know how to do this.
> Where should I add TableNewRow event handler?


It depends on a couple of things...

First, you don't mention that you are using NET2.0, the event is only
available in NET2.0, since you consider the option i assume you are.

Second, it would also be different depending on how and where you create the
DataSet/DataTable which you have bound.

And last, the language you are using.


// Assuming you are using NET2.0, you've added the
// (typed) DataSet/DataTable using the designer and are
// using C#, then you would do something like:
public partial class SomeForm : Form
{
public SomeForm()
{
InitializeComponent();

// add handler after InitializeComponent
someDataSet.someDataTable.TableNewRow +=
new DataTableNewRowEventHandler( OnSomeTable_TableNewRow );
}

private void OnSomeTable_TableNewRow( object sender,
DataTableNewRowEventArgs e )
{
// set default values
e.Row["someField1"] = ....;
e.Row["someField2"] = ...;
...
}
}

HTH,
Greetings


>
> Thanks in advance.



  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off