[Python.NET] Problem with DateTimePicker control

Peter Schwalm ps at pschwalm.de
Wed Mar 7 21:00:36 CET 2007


I have problems setting the Value of a DateTimePicker control of Windows 
Forms. The Value property *is* set (I can print it), but if displayed 
only the current date is shown in the control, not the value I have set 
the Value property set to before.

The python version is 2.3, the .net versions tested are 1.1 and 2.0.

Here are some code snippets:

def dt2SysDt(dtFrom, incr = 0):
        "python date/dateTime in .net-DateTime(Date) umwandeln"
        return (System.DateTime(dtFrom.year, dtFrom.month, dtFrom.day)

def sysDt2Dt(dtFrom, incr = 0):
        ".net-DateTime(Date) in python dateTime.date umwandeln"
        dtFrom                      = dtFrom.AddDays(incr)
        rv = datetime.date(dtFrom.Year, dtFrom.Month, dtFrom.Day)
        #print "sysDt2Dt=", rv
        return rv


       # set the value
        self.dtpErzeugtVon.Value        = dt2SysDt(src.dtErzeugtAb)

       # display the values of dtp's
        for ctl in (self.dtpErzeugtVon,   self.dtpErzeugtBis,
                    self.dtpVersendetVon, self.dtpVersendetBis):
            print "dtp...=", ctl.Name, ctl.Value, sysDt2Dt(ctl.Value)

       # the print statement shows the following
        dtp...= dtpErzeugtBis 31.03.2007 00:00:00 2007-03-31

When the form is shown with ShowDialog(), only the current date is show 
(march 7 instead of march 31).

Does anyone have an idea?

Peter Schwalm

More information about the PythonDotNet mailing list