Date Time Picker control

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike

    #1

    Date Time Picker control

    Hi to all,

    I'd like to set initial value to DateTimePicker Control
    programmaticall y, How I can do that?

    I had tried following:

    1. DataTable dt = dataLayer.GetOf fer(OfferID);
    this.dtpOfferDa te.Value =
    Convert.ToDateT ime(dt.Rows[0][6].ToString());

    2. I tried:
    this.dtpOfferDa te.Value = Convert.ToDateT ime(dt.Rows[0][6]);

    It doesnt works too, shows only current date...

    On the same time, for text box works fine...

    this.txtOfferDa te.Text = dt.Rows[0][6].ToString();

    Please help. Thanks in advance good people

  • Marc Gravell

    #2
    Re: Date Time Picker control

    Well, the code (at the bottom) works fine; I would suggest breaking
    the expression and checking the values, i.e.
    DateTime tmp = Convert.ToDateT ime(dt.Rows[0][6]);
    // breakpoint/output! what is tmp?
    this.dtpOfferDa te.Value = tmp;

    And you might want to double-check that dtpOfferDate is the correct
    control and isn't already data-bound, and doesn't have any conflicting
    min/max values.

    Marc



    using System;
    using System.Windows. Forms;

    static class Program
    {
    [STAThread]
    static void Main()
    {
    Application.Ena bleVisualStyles ();
    using (Form f = new Form())
    using (DateTimePicker dtp = new DateTimePicker( ))
    {
    dtp.Value = new DateTime(1960, 11, 13);
    f.Controls.Add( dtp);
    Application.Run (f);
    }

    }
    }

    Comment

    • Mike

      #3
      Re: Date Time Picker control



      Hi Marc,

      it's works. You are really good! Thanks.

      Sincerelly, I do not understand where is difference, but it's works.

      Thanks.
      Mike

      On Mon, 12 Nov 2007 07:27:04 -0800, Marc Gravell
      <marc.gravell@g mail.comwrote:
      >Well, the code (at the bottom) works fine; I would suggest breaking
      >the expression and checking the values, i.e.
      >DateTime tmp = Convert.ToDateT ime(dt.Rows[0][6]);
      >// breakpoint/output! what is tmp?
      >this.dtpOfferD ate.Value = tmp;
      >
      >And you might want to double-check that dtpOfferDate is the correct
      >control and isn't already data-bound, and doesn't have any conflicting
      >min/max values.
      >
      >Marc
      >
      >
      >
      >using System;
      >using System.Windows. Forms;
      >
      >static class Program
      >{
      [STAThread]
      static void Main()
      {
      Application.Ena bleVisualStyles ();
      using (Form f = new Form())
      using (DateTimePicker dtp = new DateTimePicker( ))
      {
      dtp.Value = new DateTime(1960, 11, 13);
      f.Controls.Add( dtp);
      Application.Run (f);
      }
      >
      }
      >}

      Comment

      Working...