Search code examples
vb.netdatelistboxfill

fill list box with each day from date to date vb.net


I want to add dates for everyday in list box since 1/1/2014 until the day when someone load my form,as the following:

1/Jan/2014
2/Jan/2014
3/Jan/2014
..
..
..
today's date

thanks


Solution

  • Something like this?

    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