Date Time Picker control

M

Mike

Hi to all,

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

I had tried following:

1. DataTable dt = dataLayer.GetOffer(OfferID);
this.dtpOfferDate.Value =
Convert.ToDateTime(dt.Rows[0][6].ToString());

2. I tried:
this.dtpOfferDate.Value = Convert.ToDateTime(dt.Rows[0][6]);

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

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

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

Please help. Thanks in advance good people
 
M

Marc Gravell

Well, the code (at the bottom) works fine; I would suggest breaking
the expression and checking the values, i.e.
DateTime tmp = Convert.ToDateTime(dt.Rows[0][6]);
// breakpoint/output! what is tmp?
this.dtpOfferDate.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.EnableVisualStyles();
using (Form f = new Form())
using (DateTimePicker dtp = new DateTimePicker())
{
dtp.Value = new DateTime(1960, 11, 13);
f.Controls.Add(dtp);
Application.Run(f);
}

}
}
 
M

Mike

Hi Marc,

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

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

Thanks.
Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top