Select multiple dates in DateTimePicker in vb.net?

Anyway, can I select multiple dates in the Date Time Picker in Vb.net?

+4
source share
4 answers

Use the BoldedDates property on your calendar of the month to get an array of DateTime objects. You can use this to get your collection and finally clear the bold dates after storing it so that it can be reused.

+3
source

Select multiple dates in DateTimePicker in vb.net?

If you want to select a date range using DateTimePicker, the best way is if two DateTimePicker are probably controlling the date and date.

You can then change the date of the opposite control when the first date is selected to make sure FromDate is before ToDate and vice versa

I found a MonthCalendar control that seems perfect for this purpose, but I cannot find a parameter (method, property) to get selectedDates, and then use them.

If you want to use the MonthCalendar control, you can specify the MaximumSelectionCount property, and then the user can select the dates by clicking one and clicking on another date

You can get the dates selected by the user using the SelectionRange or SelectionStart and SelectionEnd properties

How about if I want to pick random dates like February 4, 6, 10.

This is harder. Suggestion - you can use the BoldedDates MonthCalendar , and when the user clicks on the day, you highlight it in bold. Then can you read the array after they have finished their selection? Maybe someone has a suggestion for this?

+2
source
 Private listDates As List(Of DateTime) Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 'Suppose that you have the following list of dates below listDates = New List(Of DateTime)() listDates.Add(DateTime.Now) listDates.Add("12/22/2012") listDates.Add(DateTime.Now.AddDays(-10)) End Sub Protected Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As DayRenderEventArgs) Handles Calendar1.DayRender 'Set Default properties e.Day.IsSelectable = False e.Cell.BackColor = System.Drawing.Color.Gray 'Now loop through the list of dates and make it 'Selectable For Each d As DateTime In listDates Calendar1.SelectedDates.Add(d) If e.Day.IsSelected Then e.Cell.BackColor = System.Drawing.Color.Green e.Day.IsSelectable = True End If Next End Sub Protected Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e As EventArgs) Handles Calendar1.SelectionChanged 'Print the selected date Response.Write("You have selected: " & Calendar1.SelectedDate.ToShortDateString()) End Sub 

I found it and will try it. it works, the source is here

+2
source

There is no way to do this in an existing DateTimePicker control.

The best alternative solution will depend on your specific situation. What context? If you expect the user to select dates that are close to each other (and the range is not too large), a fairly simple solution is to use another control that allows you to use multi selection in the list.

For example, CheckedListBox or DataGridView .

Then fill it with a list of dates. In fact, offering the user a selection of dates.

0
source

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


All Articles