|
-
Jan 15th, 2009, 07:52 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] [2008]DateTimePicker quick question
Is there any way to use a DTP and have nothing but the slashes show until the user enters a date?
-
Jan 15th, 2009, 07:56 AM
#2
Re: [2008]DateTimePicker quick question
Not that I can see... I think you might be able to do it if you created your own control that inherited the DTP but I cant say how much work that would involve I'm afraid. Maybe someone else has a better solution.
Have you tried searching for similar questions on google?
-
Jan 15th, 2009, 08:03 AM
#3
Thread Starter
Frenzied Member
Re: [2008]DateTimePicker quick question
Yeah, but I haven't found anything that I was looking for. The user likes the DTP, ( not to forget how easy it is to code when the database item is a date, no mess converting strings) but not the fact that that there is already a date in it. She is afraid if someone gets distracted from the screen before they enter a date, when they come back they wont notice that the date was never entered because there will be text in the DTP.
I guess I could put a check in to see if they have changed the date when the form closes. If it is equal to today or if the value hasn't changed ask if they want to enter a date.
-
Jan 15th, 2009, 08:12 AM
#4
Re: [2008]DateTimePicker quick question
Hmm yeah thats the only thing I can think of really, just sticking like a boolean value in that gets set to true when the ValueChanged event of the DTP fires and then when they go to close the form if that boolean is false a warning appears.
-
Jan 15th, 2009, 09:21 AM
#5
Thread Starter
Frenzied Member
Re: [2008]DateTimePicker quick question
OK, so in the Value Changed event I have;
Code:
private void dtpPickUpDate_ValueChanged(object sender, EventArgs e)
{
hasChanged = true;
}
In the Button click where I am exiting the form I have;
Code:
private void btnReturnToMainForm_Click(object sender, EventArgs e)
{
// if we are in form Add and the Pickup Date has not been set we need to let the user know
if (this.Text == "Delivery Ticket Add Record" && this.dtpPickUpDate.ValueChanged == false)
{
MessageBox.Show("You did not select a Pickup Date. Please select one now", "No Pickup Date Selected");
return;
}
Close();
}
But I get the Error Message;
The event 'System.Windows.Forms.DateTimePicker.ValueChanged' can only appear on the left hand side of += or -=
-
Jan 15th, 2009, 09:32 AM
#6
Re: [2008]DateTimePicker quick question
I dont know much about C# operators but I think your IF statement is all wrong, it should be something like this (in VB.NET)
vb Code:
if (Me.Text = "Delivery Ticket Add Record" AndAlso Me.HasChanged = false) Then
Obviously you can just convert that to C#.NET.
Note that your HasChanged variable needs to be declared at class level so that you can refer to it from different events.
-
Jan 15th, 2009, 10:15 AM
#7
Thread Starter
Frenzied Member
Re: [2008]DateTimePicker quick question
hasChanged is a Global Variable, I use it to check all fields before exiting. But I guess if I need to check the Date changes specifically then I could do a separate variable for the Pickup Date and The Delivery Date.
-
Jan 15th, 2009, 10:20 AM
#8
Re: [2008]DateTimePicker quick question
Yeah that would be the way to do it. You cant compare an Event like you were trying to do in your IF statement as they dont produce a value
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|