The question sounds illogical, but it is not:
I have 2 dates "Target" and "Actual". Usually the "Actual" date is very close to "Target", but not necessarily to the current date. To avoid the multiple clicks in the calendar that would navigate you to the month/year of interest, I set the selected date to my "Target" date when it is opened. This works great, BUT does not allow me to select that day, with the calendar closing automatically after selecting.
Any idea to solve this or any known alternative?
If you have a Calendar1 component, you can use a code like:
DateTime tomorrow = DateTime.Today.AddDays(1);
Calendar1.TodaysDate = tomorrow;
Calendar1.SelectedDate = Calendar1.TodaysDate;
When this calendar changed SelectionChanged the selected date, you can set the other calendar.
Tell me if you need more detail.
Related
I have couple of datepicker implemented in Xaml .
- After user picks certain dates, a simple logic finds the earliest of the two dates. Also, it is not necessary for user to pick both dates.
I noticed that the "default" datepicker value if user does not pick any date is 1/1/0001.
Assuming the user picks the second date as 1/1/2017, the earliest of the two dates would always be 1/1/0001 which is not desired. In such scenario, the minimum date should be 1/1/2017.
what is the logic to neglect default date of 1/1/0001
There is a property MinYear which can be set to minimum year accepted which in your case obviously should be 2017. This will solve the problem by automatically limiting range of available values to be lower bounded by 2017-01-01 - this for UWP DatePicker.
In WPF DatePicker there is a DisplayDateStart property which can be set to minimum date available in drop down calendar which can be chosen by user. Similar property DisplayDateEnd is used for setting highest date which can be displayed in DatePicker. DatePicker.SelectedDateChanged is a very useful event which when wired up will capture changes to the dates on all instances of DatePickers and this can be used to create relations between them i.e. to enforce selection of the valid period which starts from date selected on DatePicker 1 and ends on date selected in DatePicker 2 by setting DisplayDateStart on picker 2 to date selected on picker 1 in event handler. This all together provides very high level of flexibility in controlling user input via DatePicker class.
hi i have a datepicker in my winforms and i want to disable the date exists in my dataBase?
num_reglement = date_paiement.Text + "-" + txtMatricule.Text;
paiement save_paiement = new paiement(num_reglement, double.Parse(txtmontantht.Text),
cmb_paiement.Text, txtbanque.Text, txt_cheque.Text,
date_paiement.Value.Date.ToShortDateString(), txtMatricule.Text, txtlibelle.Text);
save_paiement.insert();
I don't think date time Picker has any such property. It has Max-Date, Min-Date property if you have valid date range, if you want to validate from database ,Only way is to check in Text changed event if value exits in database and show popup of rejection.Otherwise use some third party Control.
I have a Calendar Extender.
I want to show only current year in calendar.
User can not select 2010 as current year is 2011.
So how to do this ?
Use the StartDate and EndDate properties to set a range of acceptable dates that you want to allow the user to select - you can set this in the markup as per krolik's answer, or in the code-behind so you can set it to the current year e.g.
CalendarExtender.StartDate = new DateTime(DateTime.Today.Year,1,1);
CalendarExtender.EndDate = new DateTime(DateTime.Today.Year,12,31);
Use StartDate property of your extender. For example:
<ajax:CalendarExtender ID="Calendar" StartDate="1/1/2011" runat="server" ... />
StartDate - Indicates start date for range that available for selection.
I have a button in every row of my DataGridView. When that button is clicked, a calender should be displayed in which the selected dates (I have in list) should be bolded. The dates will be different for different buttons and so the bolded dates should also be changed for every button click. Is it possible to have a tag for every bolded date?
Is the single calender is sufficient or should I declare number of month calenders for every button.
I am very new to C#, please reply me the answer.
You can reuse the same Calendar control by specifying different BoldedDates.
DateTime[] myDates = {myDate1, myDate2};
calendar.BoldedDates = myDates;
Look at here and here for more details about bold dates.
I have a date picker control that I use for a data collection application. It is using MvvM data binding. When going through a list of dates (see fig1) it will populate the date picker correctly. Whenever I hit new, the date pickers are nulled out. When I pull up the popup, it selects the month and year from the previous date that was set to. (fig 2) Is there anyway to default the pop up show the current month in the current year?
Note : I would like to keep the selected date to null on a new entry to force some validation.
Fig 1
Fig 2
The following image is to show what happens when I set the DisplayDateStart.
(original answer was horribly wrong, sorry about that)
Okay, lets try this again.
Have you tried setting the fallback to today's date?
SelectedDate="{Binding TehDate, FallbackValue={x:Static sys:DateTime.Now}}"