我想在2014年1月1日之后的列表框中添加日期,直到有人加载我的表单,如下所示:
1 /月/ 2014
2 /月/ 2014
3 /月/ 2014
..
..
..
今天的日期
感谢
答案 0 :(得分:0)
这样的东西?
Public Sub Form_Load()
FillList()
End Sub
Private Sub FillList()
Dim dWorkDate As Date = CDate("01.01.2014")
While dWorkDate < Date.Today
myListBox.Items.Add(dWorkDate.ToString("dd.MM.yyyy"))
dWorkDate = dWorkDate.AddDays(1)
End While
End Sub
答案 1 :(得分:0)
假设:
Form1
ComboBox1
的组合框控件(您可以将其更改为列表框,但我建议使用comobox以方便使用和显示)当您在其中插入表单和控件时,这些是VB给出的默认名称。只需将子文件粘贴到Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim D As Date
Dim TD As Date
Dim Count As Integer
TD = FormatDateTime(Today, DateFormat.GeneralDate)
D = #1/1/2014#
ComboBox1.Items.Add(FormatDateTime(D, DateFormat.GeneralDate).ToString)
Count = DateDiff(DateInterval.Day, D, TD)
For i As Integer = 0 To Count - 1
D = D.AddDays(1)
ComboBox2.Items.Add(FormatDateTime(D, DateFormat.GeneralDate).ToString)
Next
End Sub
输出: