DateTimePicker custom format

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 
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.
 
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.DateTime"));
for (int i = 0;i<10;i++)
{
dt.Rows.Add(dt.NewRow());
dt.Rows["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
 
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
 

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

Back
Top