在 vb.net 的 DateTimePicker 中选择多个日期?

发布于 2024-12-28 15:44:22 字数 41 浏览 1 评论 0原文

无论如何,我可以在 Vb.net 的日期时间选择器中选择多个日期吗?

Is there anyway i can select multiple dates in a Date Time Picker in Vb.net?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

请帮我爱他 2025-01-04 15:44:22

在月历中使用 BoldedDates 属性来获取 DateTime 对象的数组。您可以使用它来获取您的收藏,并在存储后最后清除粗体日期,以便可以重复使用。

Use BoldedDates Property in your month calendar to get the 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.

风向决定发型 2025-01-04 15:44:22

在 vb.net 的 DateTimePicker 中选择多个日期?

如果您想使用 DateTimePicker 选择日期范围,那么最好的方法是两个 DateTimePicker 控制一个起始日期和一个截止日期。

然后,您可以在选择第一个日期时更改相反控件的日期,以确保 FromDate 在 ToDate 之前,反之亦然

我发现 MonthCalendar 控件似乎非常适合此目的,但我找不到获取 selectedDates 然后使用它们的选项(方法、属性)。

如果您想使用 MonthCalendar 控件,您可以指定 MaximumSelectionCount 属性,然后用户可以通过单击一个日期并按住 Shift 键单击另一个日期来选择日期。

您可以检索用户使用 SelectionRangeSelectionStartSelectionEnd 属性选择的日期

如果我想选择随机日期,例如 2 月 4 日、6 日、10 日,怎么样?

这更复杂。一个建议 - 您可以使用 MonthCalendarBoldedDates 数组,当用户单击某一天时,您将其加粗。他们完成选择后您可以读取数组吗?也许其他人对此有建议?

Selecting Multiple dates in a DateTimePicker in vb.net?

If you want to select a range of dates using a DateTimePicker, then the best way if probably two DateTimePicker controls a from date and a to date.

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

I found MonthCalendar control which seems to be perfect for this purpose but i cant find the option (method, property) to get the selectedDates and then use them.

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

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

How about if i want to select random dates, like 4th, 6th, 10th Feb.

This is more complex. A suggestion - you could use the BoldedDates array of the MonthCalendar and when a user clicks on a day, you bold it. You can then read the array after they have finished their selection? Maybe someone else has a suggestion for this?

倒数 2025-01-04 15:44:22
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

我找到了,并尝试一下。它有效,
原始来源来自

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 try. it work,
original source from here

最后的乘客 2025-01-04 15:44:22

在现有 DateTimePicker 控件内无法执行此操作。

最佳替代解决方案将取决于您的具体情况。背景是什么?如果您希望用户选择接近的日期(并且范围不太大),一个相当简单的解决方案是使用另一个允许在列表上进行多重选择的控件。

例如 CheckedListBoxDataGridView

然后用日期列表填充它。实际上为用户提供了一个日期选择列表。

There is no way to do this inside the existing DateTimePicker control.

The best alternative solution will depend on your specific situation. What's the context? If you're expecting the user to pick dates which are close together (and the range isn't too big) a reasonably simple solution is to use another control which will allow multiselect on a list.

For example a CheckedListBox or DataGridView.

Then populate it with a list of dates. In effect offering the user a picklist of dates.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文