Get Timepicker Value C# WPF - c#

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.

Related

How to display selected month from Calendar into text box in WPF?

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();

Reset/ or Clear the content of CalendarDatePicker and TimePicker in UWP

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;

How do i insert value to datetimepicker by clicking datagridview cells in C#?

I was wondering if it's possible to set the value of a datetimepicker just by clicking selected row of datagridview.. and the format i want is dd-MM-yyyy. I tried ‍dateTime.Parse()‍‍ but it gave me errors.
You can try this below code on datagridview OnCellClick:
private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
{
dateTimePicker1.Value = Convert.ToDateTime(dataGridView.Rows[e.RowIndex].Cells["The Column"].Value);
}

Updating textbox based on datagrid view

I have this datagrid view which links to the table answers in the database. The user can edit answers to questions in this form, but I'd like for the textbox to be updated as the button moves onto next answer. This is so the user can edit/delete stuff in the textbox and save it.
private void NextQuestion_Click(object sender, EventArgs e)
{
QuestionsBindingSource.MoveNext();
}
How can I get the textbox to refresh based on selected record in datagridview?
Since you are using a BindingSource, you can get the Current object, cast it to it's type, and get a value.
Let's assume you are bound to a DataTable:
private void NextQuestion_Click(object sender, EventArgs e)
{
if (QuestionsBindingSource != null)
{
QuestionsBindingSource.MoveNext();
if (QuestionsBindingSource.Current != null)
{
DataRow row = (DataRow)QuestionBindingSource.Current;
yourTextBox.Text = row["FieldYouWant"].ToString();
}
}
}
What you cast Current to and the subsequent value reference are both dependent upon what you are bound to (what QuestionsBindingSource is). Adjust this example accordingly.

How to force a numeric textbox control not to accept empty string?

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";
}
}

Categories