469,269 Members | 1,006 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

DateTimePicker custom format

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
4 15489
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
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
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
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.

Similar topics

reply views Thread by E-Cube | last post: by
2 posts views Thread by Atley | last post: by
3 posts views Thread by M K | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.