Is there any way to use a DTP and have nothing but the slashes show until the user enters a date? :confused:
Printable View
Is there any way to use a DTP and have nothing but the slashes show until the user enters a date? :confused:
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?
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.
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.
OK, so in the Value Changed event I have;
In the Button click where I am exiting the form I have;Code:private void dtpPickUpDate_ValueChanged(object sender, EventArgs e)
{
hasChanged = true;
}
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 -=
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)
Obviously you can just convert that to C#.NET.vb Code:
if (Me.Text = "Delivery Ticket Add Record" AndAlso Me.HasChanged = false) Then
Note that your HasChanged variable needs to be declared at class level so that you can refer to it from different events.
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.
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