473,387 Members | 1,882 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 15671
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: E-Cube | last post by:
Hello All, I have a datetimepicker whose initial format is: DateTimePicker1.Format = DateTimePickerFormat.Custom DateTimePicker1.CustomFormat = " " DateTimePicker1.Checked = False which will...
9
by: Guy | last post by:
I have extended the datetimepicker control to incorporate a ReadOnly property. I have used the new keyword to implement my own version of the value property, so that if readonly == true then it...
2
by: Atley | last post by:
Is there a way to use the DateTimePicker to pick a time or is it just used to pick dates? If so, why is it called DATEtimepicker?
2
by: andreas | last post by:
Hi, I have a datetimepicker , format set to time and two strings, the first give me a hour lke "5" and the other the minutes like "15" How can i put these two values in the datetimepicker ?...
2
by: Robin Tucker | last post by:
I'm using the date/time picker to allow users to choose a date or a time. However, as the control modes only allow one or the other, I'm scratching my head as to how to allow the one control to...
3
by: M K | last post by:
Can you initialize the DateTimePicker to "" or Null? I want the date to be optional so it should be blank at first unless the user selects a date. If not, is there another solution? Mark
2
by: Claes Wedin | last post by:
My customer needs a DateTimePicker in VS2005 C# that can show emty date values (blank/space/null). I need a control that: 1. Can show a blank value 2. Detete a date when hitting the delete...
2
by: KA NMC | last post by:
I've noticed something strange when using the code below with a DateTimePicker wondering anyone else noticed or knows why this happens Dim ws As String ws = "Not Available" ...
0
by: tschroeder250 | last post by:
Hi Everyone, There are so many Nullable DateTimePickers out there that this post may not even be found among all the others, but I wanted to try. First, I want to thank all the authors of the...
0
by: priyamtheone | last post by:
I'm trying to make a datagridview column to act like a datetimepicker column (C#.Net 2005). These are the behaviours that the dgv should have: 1) Initially all the cells of the dtp column should be...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.