468,321 Members | 1,820 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,321 developers. It's quick & easy.

DateTimePicker & Databinding

Is there a cure for the problems using databinding with a DateTimePicker?

I find that a) sometimes it works, sometimes it doesn't, and b) it fails
silently causing all databinding on the DataSet to fail with a error message.

Help!
Nov 17 '05 #1
6 6259
See my article of January 2005 from http://pages.videotron.com/emoreau/

--
HTH

Éric Moreau, MCSD, Visual Developer - Visual Basic MVP
(http://aspnet2.com/mvp.ashx?EricMoreau)
Conseiller Principal / Senior Consultant
Concept S2i inc. (www.s2i.com)
http://pages.videotron.com/emoreau/

"eye5600" <ey*****@discussions.microsoft.com> wrote in message
news:97**********************************@microsof t.com...
Is there a cure for the problems using databinding with a DateTimePicker?

I find that a) sometimes it works, sometimes it doesn't, and b) it fails
silently causing all databinding on the DataSet to fail with a error
message.

Help!

Nov 17 '05 #2
An interesting article, but it does not answer the question of why
databinding on the form fails when the datetimepicker has binding set, but
works when the binding is removed. None of the database fields are null, by
the way.

"Eric Moreau" wrote:
See my article of January 2005 from http://pages.videotron.com/emoreau/

--
HTH

Éric Moreau, MCSD, Visual Developer - Visual Basic MVP
(http://aspnet2.com/mvp.ashx?EricMoreau)
Conseiller Principal / Senior Consultant
Concept S2i inc. (www.s2i.com)
http://pages.videotron.com/emoreau/

"eye5600" <ey*****@discussions.microsoft.com> wrote in message
news:97**********************************@microsof t.com...
Is there a cure for the problems using databinding with a DateTimePicker?

I find that a) sometimes it works, sometimes it doesn't, and b) it fails
silently causing all databinding on the DataSet to fail with a error
message.

Help!


Nov 17 '05 #3
Hi

One of my sample is bound and it is working. It has to be something you did.

Is your field defined as a date field ?

--
HTH

Éric Moreau, MCSD, Visual Developer - Visual Basic MVP
(http://aspnet2.com/mvp.ashx?EricMoreau)
Conseiller Principal / Senior Consultant
Concept S2i inc. (www.s2i.com)
http://pages.videotron.com/emoreau/

"eye5600" <ey*****@discussions.microsoft.com> wrote in message
news:E8**********************************@microsof t.com...
An interesting article, but it does not answer the question of why
databinding on the form fails when the datetimepicker has binding set, but
works when the binding is removed. None of the database fields are null,
by
the way.

"Eric Moreau" wrote:
See my article of January 2005 from http://pages.videotron.com/emoreau/

--
HTH

Éric Moreau, MCSD, Visual Developer - Visual Basic MVP
(http://aspnet2.com/mvp.ashx?EricMoreau)
Conseiller Principal / Senior Consultant
Concept S2i inc. (www.s2i.com)
http://pages.videotron.com/emoreau/

"eye5600" <ey*****@discussions.microsoft.com> wrote in message
news:97**********************************@microsof t.com...
> Is there a cure for the problems using databinding with a
> DateTimePicker?
>
> I find that a) sometimes it works, sometimes it doesn't, and b) it
> fails
> silently causing all databinding on the DataSet to fail with a error
> message.
>
> Help!


Nov 17 '05 #4
> One of my sample is bound and it is working. It has to be something you did.
Is your field defined as a date field ?


Thank you for your interest. In fact, it work fine when first developed. I
then worked on other aspects of the program, and when I returned to this
form, it no longer worked. The field I am using for illustration is birthdate
(named "birth") which is a datetime in the SqlServer database running on my
laptop. There are no nulls in this column in the database. In fact, I made
the field non-nullable, and re-created the DataSet.

Let me throw in all the info.

The DateTimePicker is configured by the following lines created by the IDE.

//
// dtpBirth
//
this.dtpBirth.Format = System.Windows.Forms.DateTimePickerFormat.Short;
this.dtpBirth.Location = new System.Drawing.Point(176, 112);
this.dtpBirth.Name = "dtpBirth";
this.dtpBirth.Size = new System.Drawing.Size(152, 27);
this.dtpBirth.TabIndex = 2;

For debuggin purposes, I moved the databinding to the bottom of the
constructor:

Binding b = new System.Windows.Forms.Binding("Value",
this.dsRmaAcct1, "rma_account.birth") ;
b.Format += new ConvertEventHandler(dtpFormatter) ;
b.Parse += new ConvertEventHandler(dtpParser) ;
this.dtpBirth.DataBindings.Add(b);

The eventhandlers were added for debugging purposes. If I include these
lines, the databinding fails for all controls bound to the same DataTable,
but binding works for controls bound to another table in the same DataSet.
By "fails", I mean that the data from the database is not displayed in the
controls when the record is created in the DataTable. I've checked that the
data is there, the row to display is correct, etc. Attempts to display the
data via CurrencyManager refresh have not helped. The Format event handler is
NOT called. (I changed the above lines to a different contol to test that
they are created properly.) I get the same effects using any of the datetime
fields, so "birth" is not unique.

The DataTable is created in the dataset by the following from the
IDE-created XML:

<xs:element name="rma_account">
<xs:complexType>
<xs:sequence>
<xs:element name="plan_id" type="xs:string" minOccurs="0" />
<xs:element name="rma_account" type="xs:string" />
<xs:element name="ssn" type="xs:string" />
<xs:element name="first" type="xs:string" minOccurs="0" />
<xs:element name="mi" type="xs:string" minOccurs="0" />
<xs:element name="last" type="xs:string" minOccurs="0" />
<xs:element name="addr1" type="xs:string" minOccurs="0" />
<xs:element name="addr2" type="xs:string" minOccurs="0" />
<xs:element name="city" type="xs:string" minOccurs="0" />
<xs:element name="state" type="xs:string" minOccurs="0" />
<xs:element name="zipcode" type="xs:string" minOccurs="0" />
<xs:element name="phone" type="xs:string" minOccurs="0" />
<xs:element name="country" type="xs:string" minOccurs="0" />
<xs:element name="birth" type="xs:dateTime" />
<xs:element name="sex" type="xs:string" minOccurs="0" />
<xs:element name="eff_dt" type="xs:dateTime" minOccurs="0" />
<xs:element name="can_dt" type="xs:dateTime" minOccurs="0" />
<xs:element name="init_amt" type="xs:decimal" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>

I found one other post on the board from someone with the same problem, but
did not get any replies. In my case, the workaround is pretty easy, but the
program is supposed to work, damn it.
Nov 17 '05 #5
You have set the Format property of your control to Short. Do you need the
Parse and Format event handlers? If you are using them, I think you would be
better using a Custom format.

--
HTH

Éric Moreau, MCSD, Visual Developer - Visual Basic MVP
(http://aspnet2.com/mvp.ashx?EricMoreau)
Conseiller Principal / Senior Consultant
Concept S2i inc. (www.s2i.com)
http://pages.videotron.com/emoreau/

"eye5600" <ey*****@discussions.microsoft.com> wrote in message
news:93**********************************@microsof t.com...
One of my sample is bound and it is working. It has to be something you
did.
Is your field defined as a date field ?


Thank you for your interest. In fact, it work fine when first developed. I
then worked on other aspects of the program, and when I returned to this
form, it no longer worked. The field I am using for illustration is
birthdate
(named "birth") which is a datetime in the SqlServer database running on
my
laptop. There are no nulls in this column in the database. In fact, I made
the field non-nullable, and re-created the DataSet.

Let me throw in all the info.

The DateTimePicker is configured by the following lines created by the
IDE.

//
// dtpBirth
//
this.dtpBirth.Format = System.Windows.Forms.DateTimePickerFormat.Short;
this.dtpBirth.Location = new System.Drawing.Point(176, 112);
this.dtpBirth.Name = "dtpBirth";
this.dtpBirth.Size = new System.Drawing.Size(152, 27);
this.dtpBirth.TabIndex = 2;

For debuggin purposes, I moved the databinding to the bottom of the
constructor:

Binding b = new System.Windows.Forms.Binding("Value",
this.dsRmaAcct1, "rma_account.birth") ;
b.Format += new ConvertEventHandler(dtpFormatter) ;
b.Parse += new ConvertEventHandler(dtpParser) ;
this.dtpBirth.DataBindings.Add(b);

The eventhandlers were added for debugging purposes. If I include these
lines, the databinding fails for all controls bound to the same DataTable,
but binding works for controls bound to another table in the same DataSet.
By "fails", I mean that the data from the database is not displayed in the
controls when the record is created in the DataTable. I've checked that
the
data is there, the row to display is correct, etc. Attempts to display the
data via CurrencyManager refresh have not helped. The Format event handler
is
NOT called. (I changed the above lines to a different contol to test that
they are created properly.) I get the same effects using any of the
datetime
fields, so "birth" is not unique.

The DataTable is created in the dataset by the following from the
IDE-created XML:

<xs:element name="rma_account">
<xs:complexType>
<xs:sequence>
<xs:element name="plan_id" type="xs:string" minOccurs="0" />
<xs:element name="rma_account" type="xs:string" />
<xs:element name="ssn" type="xs:string" />
<xs:element name="first" type="xs:string" minOccurs="0" />
<xs:element name="mi" type="xs:string" minOccurs="0" />
<xs:element name="last" type="xs:string" minOccurs="0" />
<xs:element name="addr1" type="xs:string" minOccurs="0" />
<xs:element name="addr2" type="xs:string" minOccurs="0" />
<xs:element name="city" type="xs:string" minOccurs="0" />
<xs:element name="state" type="xs:string" minOccurs="0" />
<xs:element name="zipcode" type="xs:string" minOccurs="0" />
<xs:element name="phone" type="xs:string" minOccurs="0" />
<xs:element name="country" type="xs:string" minOccurs="0" />
<xs:element name="birth" type="xs:dateTime" />
<xs:element name="sex" type="xs:string" minOccurs="0" />
<xs:element name="eff_dt" type="xs:dateTime" minOccurs="0" />
<xs:element name="can_dt" type="xs:dateTime" minOccurs="0" />
<xs:element name="init_amt" type="xs:decimal" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>

I found one other post on the board from someone with the same problem,
but
did not get any replies. In my case, the workaround is pretty easy, but
the
program is supposed to work, damn it.


Nov 17 '05 #6
> You have set the Format property of your control to Short. Do you need the
Parse and Format event handlers? If you are using them, I think you would be
better using a Custom format.


The event handlers were added only for debugging. Nothing changes when they
are removed. They do not execute, or have any noticeable effect. The changing
the Format between Long & Short has no effect on the binding problem.
Nov 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Gary Miller | last post: by
1 post views Thread by Vik | last post: by
2 posts views Thread by Austin T | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.