By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,636 Members | 1,693 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,636 IT Pros & Developers. It's quick & easy.

DateTimePicker custom format

P: n/a
Using the custom format "ddd MMMM d h:mm tt".

DataBindings.Text is set to my dataset field.

Control displays properly, I am able to change date values but the moment I
click the save button, text field resets to database value. Debugged the
first statement in the click event.

If I do not use the custom format everything works.

Any ideas


Nov 16 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Gary,

I don't understand what you mean with this.
text field resets to database value.


The database value is nothing more than a value in ticks beginning at a
certain startdate.

Can you clear this a little bit more?

Cor
Nov 16 '05 #2

P: n/a
When the form is initiated the DateTimePicker control has what the database
has in it and in the correct format (see first post).

Fri February 18 5:00 PM

Then I change any of the values either through the drop-down calendar or
directly on the control eg - Fri February 18 6:00 PM

I have a button for 'Save' that has a click event. If I debug the first
statement in the click event method, the control 'Text' and 'Value' field
does NOT reflect the changes. And the form control is 'reset' to the
original value.

It appears as though something 'under the covers' has reset the field.
There are NO statements that I can debug on before my click event.

Thanks for your time.

"Cor Ligthert" wrote:
Gary,

I don't understand what you mean with this.
text field resets to database value.


The database value is nothing more than a value in ticks beginning at a
certain startdate.

Can you clear this a little bit more?

Cor

Nov 16 '05 #3

P: n/a
Garry,

I tried it with this piece of code and did not see anything strange.

Maybe you can try it yourself it only needs a new form wiht a datatimepicker
and a button and paste than this piece of code.

DataTable dt;
private void Form3_Load(object sender, System.EventArgs e)
{
dt = new DataTable();
dt.Columns.Add("Gary",Type.GetType("System.DateTim e"));
for (int i = 0;i<10;i++)
{
dt.Rows.Add(dt.NewRow());
dt.Rows[i]["Gary"] = DateTime.Now.AddDays(i);
}
dateTimePicker1.DataBindings.Add("Value",dt,"Gary" );
dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = "ddd MMMM d h:mm tt";
}
private void button1_Click(object sender,
System.EventArgs e)
{
CurrencyManager cm = (CurrencyManager) BindingContext[dt];
if (cm.Position>8) cm.Position = -1;
cm.Position++;
}
private void dateTimePicker1_ValueChanged
(object sender, System.EventArgs e)
{
BindingContext[dt].EndCurrentEdit();
}

I hope this helps a little bit?

Cor
Nov 16 '05 #4

P: n/a
Cor,

Thanks for your time. I am sure the example works.

My code is has 2 tables in a list/detail relationship. If I try and use the
'Value'' binding I get an exception saying that not all variable can be bound.

Another problem I am working on.

I thought I could get a round it using the 'Text'. I'll try debugging on
the dateTimePicker1_ValueChanged an see any difference.

Thanks

"Cor Ligthert" wrote:
Garry,

I tried it with this piece of code and did not see anything strange.

Maybe you can try it yourself it only needs a new form wiht a datatimepicker
and a button and paste than this piece of code.

DataTable dt;
private void Form3_Load(object sender, System.EventArgs e)
{
dt = new DataTable();
dt.Columns.Add("Gary",Type.GetType("System.DateTim e"));
for (int i = 0;i<10;i++)
{
dt.Rows.Add(dt.NewRow());
dt.Rows[i]["Gary"] = DateTime.Now.AddDays(i);
}
dateTimePicker1.DataBindings.Add("Value",dt,"Gary" );
dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = "ddd MMMM d h:mm tt";
}
private void button1_Click(object sender,
System.EventArgs e)
{
CurrencyManager cm = (CurrencyManager) BindingContext[dt];
if (cm.Position>8) cm.Position = -1;
cm.Position++;
}
private void dateTimePicker1_ValueChanged
(object sender, System.EventArgs e)
{
BindingContext[dt].EndCurrentEdit();
}

I hope this helps a little bit?

Cor

Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.