0

I have a datetime picker in windows form. When i am selecting a date it shows the last selected date and current date. But i want to shows only current date always. It should not show last selected date and current date(both) on the selection dropdown.

public FieldControl()
{
    InitializeComponent();  
    dtpDate.Value = DateTime.Now;
}
flx
  • 14,146
  • 11
  • 55
  • 70
user3319384
  • 35
  • 1
  • 11
  • I think you want the control to show only the current date selected during the selection, right? As opposed to the default behavior which shows a blue border for the current date and the selection on the previous selection. – David Feb 26 '14 at 09:59
  • @David yes i want only current date only.Not previous selected date – user3319384 Feb 26 '14 at 10:24
  • Man this is really hard as the calendar is not refreshing after opening. Do you want to keep the option of selecting the date without the calendar? – David Feb 26 '14 at 12:35

3 Answers3

0

Hello Kumar is right, but what is sense of selectable date and time component where is only one option to select? Isn't better to make datetimepicker disabled? At least it's less confusing for user and by default actual date is selected when datetimepicker is dispayed.

Jaroslav

Jaroslav Kubacek
  • 1,387
  • 18
  • 26
0

Try this :

you can get just today's date as a DateTime using the Today property:

dtpDate.Value = DateTime.Today;

if you want to show only current date in your datepicker then use this code:

dtpDate.MinDate = dtpDate.MaxDate = DateTime.Now;

For more information

Refer this link

Community
  • 1
  • 1
Govinda Rajbhar
  • 2,926
  • 6
  • 37
  • 62
0

You can't do it on the picker. But you can fake it. Resize the dateTimePicker so it only shows the pick button. Then place it next to a textbox. In the onClose event you write the selected value to the textbox, and set the value of the dateTimePicker back to Today.

David
  • 853
  • 8
  • 24
  • Yes i have placed a textbox on datepicker.when i select a date in datepicker it will enter in textbox.but my aim is to display current date always.No last selected date should be display – user3319384 Feb 26 '14 at 13:41
  • Always? Then what do you want with the selected time? I think I'm making it much harder than it's supposed to be. If you just want to display the current date just add the current date to the textbox and update it on a timer. – David Feb 26 '14 at 15:32