我有一个带有2个datetimepicker组件(d1,d2)的VB表单,7个用于星期几的复选框和一个datagridview
我需要能够指定日期范围(即2017-01-01至2017-01-31)并选择星期几(即基于复选框的星期一和星期三),datagridview将是充满该日期范围的所有星期一和星期三。
拜托,我非常感谢帮助,因为我对VB.NET中的日期功能并不那么强大。
非常感谢, ITJunior
答案 0 :(得分:0)
这可能看起来像......
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim startDate As Date = d1.Value.Date ' removes any time values
Dim stopDate As Date = d2.Value.Date ' removes any time values
If stopDate >= startDate Then
Dim DayChecked As Boolean
While startDate <= stopDate
Select Case startDate.DayOfWeek
Case DayOfWeek.Sunday
DayChecked = cbSunday.Checked
Case DayOfWeek.Monday
DayChecked = cbMonday.Checked
Case DayOfWeek.Tuesday
DayChecked = cbTuesday.Checked
Case DayOfWeek.Wednesday
DayChecked = cbWednesday.Checked
Case DayOfWeek.Thursday
DayChecked = cbThursday.Checked
Case DayOfWeek.Friday
DayChecked = cbFriday.Checked
Case DayOfWeek.Saturday
DayChecked = cbSaturday.Checked
End Select
If DayChecked Then
' ... add startDate to your DataGridView ...
Debug.Print(startDate.ToString)
End If
startDate = startDate.AddDays(1)
End While
End If
End Sub