Results 1 to 8 of 8

Thread: [RESOLVED] [2008]DateTimePicker quick question

  1. #1

    Thread Starter
    Frenzied Member CoachBarker's Avatar
    Join Date
    Aug 2007
    Location
    Central NY State
    Posts
    1,121

    Resolved [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?
    Thanks
    CoachBarker

    Code Bank Contribution
    Login/Manage Users/Navigate Records
    VB.Net | C#

    Helpful Links: VB.net Tutorial | C Sharp Tutorial | SQL Basics

  2. #2
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    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?
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  3. #3

    Thread Starter
    Frenzied Member CoachBarker's Avatar
    Join Date
    Aug 2007
    Location
    Central NY State
    Posts
    1,121

    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.
    Thanks
    CoachBarker

    Code Bank Contribution
    Login/Manage Users/Navigate Records
    VB.Net | C#

    Helpful Links: VB.net Tutorial | C Sharp Tutorial | SQL Basics

  4. #4
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    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.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  5. #5

    Thread Starter
    Frenzied Member CoachBarker's Avatar
    Join Date
    Aug 2007
    Location
    Central NY State
    Posts
    1,121

    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 -=
    Thanks
    CoachBarker

    Code Bank Contribution
    Login/Manage Users/Navigate Records
    VB.Net | C#

    Helpful Links: VB.net Tutorial | C Sharp Tutorial | SQL Basics

  6. #6
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    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:
    1. 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.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  7. #7

    Thread Starter
    Frenzied Member CoachBarker's Avatar
    Join Date
    Aug 2007
    Location
    Central NY State
    Posts
    1,121

    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.
    Thanks
    CoachBarker

    Code Bank Contribution
    Login/Manage Users/Navigate Records
    VB.Net | C#

    Helpful Links: VB.net Tutorial | C Sharp Tutorial | SQL Basics

  8. #8
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    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
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width