How to configure winform to select date and time for default value?

I am using the search function in WinForms and I am searching by date range. So the form has dateForm and dateTo date pickers. By default, their values ​​are the time date (), and if the user does not touch the time selections, he will not get any results. Since the search will be performed between now () and now (), also if I put the min and max values ​​by default, it would solve the first problem, but there would be another problem, if the user wants to search by date range, he will need to click many times from a value of 1700 (something) to now ()

Any suggestions for resolving this issue?

Many thanks.

+4
source share
5 answers

You cannot have a useless finisher with a ready-made control. What for? It is supported by DateTime, which is not null.

You can disable it using another control or leave it disabled until the user presses (bad UX for keyboard enthusiasts, for example myself), or find or create (!) That uses a Nullable<DateTime> .

Edit:

In response to your comment, yes, you can do it; in fact, I did it.

  • use fields or private properties to store the dates 'from' and 'to' instead of reading them from dtp and set their default values ​​to min and max
  • use a boolean flag indicating when you control the dtp value in the code and set the flag value to false in the dtp ValueChanged event
  • in the form load event, set the flag to true and the dtp value today
  • also in the ValueChanged event ValueChanged set the from and to fields to dtps values ​​(you must set both parameters when dtp changes, because the user will see another one set to date, but the search value will still be minimum or maximum).

The problem with this is that as soon as the user has changed the date selection, she cannot easily return to "all dates". In addition, the user cannot select β€œtoday only” without changing one of the dates and then changing it.

I believe that the best solution for you is the checkbox "search by date range", which either allows you to disable two dtps, or display hidden dtps. Then you search from min to max if the checkbox is unchecked and when the checkbox is checked, you use two dtp dates no matter what they represent. Remember to deal with to and from out of order, which can be done in several ways.

+2
source

Look here for a parameter with a null datetimepicker in CodeProject, there are actually a few here .

+2
source

Check the box next to each date and time collector and check the box to enable / disable the data collector.

So, if the datetimepicker is disabled, you know that the user does not want to specify the date and time.

+1
source

DateTimePicker has a ShowCheckBox property that "Determines whether the checkbox is displayed in the control. When the checkbox is cleared, the value is not selected."

I used something like the following for date range selectors that may be empty. One user told me that at first she did not know what the checkbox was for, but she herself understood this after using this a couple of times.

 public DateTime? EndDate { get { DateTime? returnValue = null; if (endDateDateTimePicker.Checked) { returnValue = endDateDateTimePicker.Value; } return returnValue; } set { if (value.HasValue) { endDateDateTimePicker.Checked = true; endDateDateTimePicker.Value = value.Value; } else { endDateDateTimePicker.Checked = false; } } } 
0
source

You can set the DateDateTimePicker.format property to custom. Then, in the DateDateTimePicker.customformat property, you can set the default text, for example, "N / A" or sapce "". After the user has selected a specific date value, you should return the format property to short, etc.

http://i.stack.imgur.com/Z1QB5.png

Hope this helps!

0
source

Source: https://habr.com/ru/post/1299607/


All Articles