how can I reset or clear the content of CalendarDatePicker and/or TimePicker in UWP? I want to create a button (ex. RESET), when I click on the button, the CalendarDatePicker and TimePicker will clear the date and time which was selected before and will show back the PlaceHolder Text. I could not find any methods to do this. Is there a way? Thanks...
Try to set the Date property of the CalendarDatePicker or the SelectedTime property of the TimePicker to null:
private void Button_Click(object sender, RoutedEventArgs e)
{
calendarDatePicker1.Date = null;
timePicker1.SelectedTime = null;
}
In case anyone else comes across this, you have to set the SelectedDate for DatePicker or SelectedTime for TimePicker to null.
For example:
(FindName("myDatePickerName") as DatePicker).SelectedDate = null;
Related
I wanted to ask how can I display selected month from calendar and display into my text box? I tried to use ToString(), but it still didn't work. I'm thinking there's difference in date picker and calendar, still not sure. Can anyone please help me out here? Thanks alot. Here's my coding;
In xaml;
Calendar Name ="dteSelectedMonth" DisplayMode="Year" SelectionMode="SingleDate" DisplayModeChanged="dteSelectedMonth_DisplayModeChanged" DisplayDateChanged="monthCalendar_DataChanged"
In xaml.cs;
private void monthCalendar_DataChanged(object sender, CalendarDateChangedEventArgs e)
{
monthDisplay.Text = dteSelectedMonth.SelectedDate.ToString();
}
You could get the selected month using the DisplayDate property. Make sure that the IsLoaded property returns true before you try to set the Text property:
private void monthCalendar_DataChanged(object sender, CalendarDateChangedEventArgs e)
{
if (IsLoaded && dteSelectedMonth.DisplayDate != null)
monthDisplay.Text = dteSelectedMonth.DisplayDate.ToString("MMM");
}
Use CalendarDateChangedEventArgs object and its property AddedDate. When the event is fired, it will contain the previously selected day in the new month. Then you can convert it to any string format, e.g. to get the month.
Please check your monthDisplay textbox is null or not. This happens because the displayDteChanged event fires before the initialization of the textbox (If you have the declaration of TextBox before that of Calendar). Add a null check to handle this.
if (monthDisplay != null)
monthDisplay.Text = e.AddedDate?.Month.ToString();
datetimepicker.Value or datetimepicker.Text is always returning the current DateTime, not the selected one. Is there any property that I need to set to get the selected date time.
Below is my code:
private void button1_Click(object sender, EventArgs e)
{
c1.cName = textBox1.Text;
c1.dlv_Time = dateTimePicker1.Value;
string temp = dateTimePicker1.Text;
textBox1.Text = "";
dateTimePicker1.Text = "";
}
In the Form UI, I am changing the time, but in the code Im always receiving the present time.
Thanks in advance
dateTimePicker1.Value.TimeOfDay.ToString()
It will return you the selected time of the date picker control in the string format.
I was editing a different timepicker and reading from a different timepicker.
I have resolved it by changing datetimepicker1 to datetimepicker2.
I have a timepicker control from Xceed WPF toolkit.
1. How i can get user selected time input value from it and put it in a textbox?
2. How i can add some integer value stored in a variable and add them as minutes to the timepicker time?
Thanks
private void textBox1_TextChanged(object sender, TextChangedEventArgs e)
{
mytimepicker = new TimePicker();
if (mytimepicker.Value != null)
{
textBox1.Text = mytimepicker.Value.ToString();
}
}
This shows how to use the Xceed DatePicker:
http://www.c-sharpcorner.com/uploadfile/mahesh/wpf-datepicker/
You want to watch the SelectedDatesChanged event.
I'm probably missing something obvious but I can't see it.....
I have a DateTimePicker control (Winforms) to display just the Time HH:mm:ss of the DateTime. The properties are as follows
Checked = False
Format = Time
ShowCheckbox = False
ShowUpDown = True
Value = 28/10/2014 08:00
ApplicationSettings.PropertyBinding.Value = pickTime1
Where pickTime1 is a user setting where Properties.Settings.Default.pickTime1 = 28/10/2014 08:00
I'm expecting the control to display 08:00:00 when the form first loads but it displays the current time. How do I ensure the user setting is displayed when first initialized?
Subscribe to the Form.Load event and set it in there:
private void Form1_Load(object sender, EventArgs e)
{
dateTimePicker1.Value = Properties.Settings.Default.pickTime1;
}
This will display 8:00:00 AM.
If you want 08:00:00, change Format to Custom, and set the CustomFormat property to "hh:mm:ss".
The DateTimePicker.Value must be changed either by code or by user input, otherwise it will set to the current date and time (i.e. DateTime.Now)
I have a winform app.
I am using a numeric textbox control.
My problem is that I can erase the value and leave the control.
When I do that - the value that was before I delete it is the value of the control,
but the display is an empty value.
It is important to mention - The default value of the controls is 0.
I would like that if the user deletes the value of the control , I would like to set the value of the control to 0.
My question is :
How can I force a numeric textbox control not to display an empty value ??
Thanks .
well, you can write a simple validation
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(textBox1.Text))
{
textBox1.Text = "0";
}
}