user962206
user962206

Reputation: 16147

Setting the Date Time Picker to blank or 0 value

I have this form right here, where the user will add the start date of the diagnosis. pretty simple right? but in the end diagnosis how would I set it to a blank? or 0 value? here's my form.enter image description here

Upvotes: 0

Views: 11477

Answers (7)

Chaos
Chaos

Reputation: 685

All solved now just had to adjust. As what you guys were saying i wasn't setting the value or the properties so it would all ways be null anyway

private string _BirthDate;

        public Form1()
        {
            InitializeComponent();
            dateTimePicker1.MaxDate = DateTime.Now; // Ensures no future dates are set.
            dateTimePicker1.Format = DateTimePickerFormat.Custom;
            //dateTimePicker1.Checked = true;
            dateTimePicker1.CustomFormat = dateTimePicker1.CustomFormat;
            dateTimePicker1.Value = DateTime.Now;
        }
        public string BirthDate
        {
            set
            {
                if (dateTimePicker1.Value.Date == DateTime.Today)
                {
                    dateTimePicker1.CustomFormat = " ";

                }
                else
                {
                    _BirthDate = value;
                }
            }
            get { return _BirthDate; }
        }


        private void button1_Click(object sender, EventArgs e)
        {

           BirthDate = dateTimePicker1.Value.ToString();
        }

Upvotes: 0

rutchel
rutchel

Reputation: 21

i think, it is not possible to set it as blank or 0 value.. the least you can do is to set it in its MinDate if it's null..

this one works for me..

 dateTimePicker1.Format = DateTimePickerFormat.Custom;

 dateTimePicker1.CustomFormat = " ";

Upvotes: 2

Mujassir Nasir
Mujassir Nasir

Reputation: 1730

try to use

dateTimePicker1.Value.Date

It would return you only date

Upvotes: 0

Alex
Alex

Reputation: 758

You can put an external checkbox and disable the datetimepicker when you wish to signify no-date.

Upvotes: 0

Devin M
Devin M

Reputation: 9752

Try setting the Value property. However I think there is a limit on how far back you can set the value.

Upvotes: 0

Thomas Levesque
Thomas Levesque

Reputation: 292545

The best you can do is to set ShowCheckBox to true. If the CheckBox is not checked, consider that no end date is set.

Upvotes: 4

Dani
Dani

Reputation: 15069

you don't want it to be set to 0. It makes no sense (1/1/01 ? most of DB doesn't event store this date)

You should put it either the same as start or in a reasonable margin which describe the common scenario (like + 2 weeks)

Upvotes: 1

Related Questions