?
Solved

populating drop downs

Posted on 2006-10-27
5
Medium Priority
?
184 Views
Last Modified: 2010-04-23
I've got 2 dropdowns. 1 is populated with years (ie. 2006, 2005, 2004, etc.)
the other one i want to populate with dates base on those years.

if dropdown1 = 2006 then
dropdown 2 will be filled with every sunday date from October 1 2005 - September 30 2006
09/24/2006
09/17/2006
09/10/2006
and so on all the way to
10/02/2005


if dropdown1 = 2005 then
dropdown2 will be filled with every sunday date from October 1 2004 - September 30 2005

how do i do this?

TIA
0
Comment
Question by:Mike Miller
  • 2
  • 2
5 Comments
 
LVL 17

Assisted Solution

by:ZeonFlash
ZeonFlash earned 400 total points
ID: 17819890
Does something like this work for you?

      Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
            Dim startDate, endDate As Date

            startDate = New Date(ComboBox1.Text, 10, 1).AddYears(-1)
            endDate = New Date(ComboBox1.Text, 9, 30)

            FillDates(startDate, endDate)

      End Sub

      Private Sub FillDates(ByVal startDate As Date, ByVal endDate As Date)
            While Not startDate.DayOfWeek = DayOfWeek.Sunday
                  startDate = startDate.AddDays(1)
            End While

            While DateDiff(DateInterval.Day, startDate, endDate) > 0
                  ComboBox2.Items.Add(startDate.ToShortDateString)
                  startDate = startDate.AddDays(7)
            End While
      End Sub
0
 

Author Comment

by:Mike Miller
ID: 17820079
maybe something like that...
let's assume that the 1st drop down is already populated with the year (only the year, ie. 2006, 2005, 2004, etc.)
0
 
LVL 17

Expert Comment

by:ZeonFlash
ID: 17820134
Yup, that's what the code assumes.  Combobox1 has values like 2006, so when the a new item is selected, it creates the start and end dates.  The start date is created by taking October 1 of the year selected (ie Combobox1.Text), and then subtracting a year.  

So if 2006 is selected from Combobox1:
  1 - Create a start date - 10/1/2006
  2 - Subtract a year - 10/1/2005

The end date is created the same way, except without subtracting a year.
0
 
LVL 35

Expert Comment

by:YZlat
ID: 17820148
is it a web or windows application?
0
 
LVL 35

Accepted Solution

by:
YZlat earned 1600 total points
ID: 17820291
put the following code in the SelectedIndexChanged event of the first dropdown:

Dim dtStart, dtEnd, dt As DateTime
        Dim tempDate As String
        Dim n As Integer
        tempDate = "10/01/" &  Dropdown1.SelectedValue.ToString
        dtStart = DateAdd(DateInterval.Year, -1, CDate(tempDate))
        tempDate = "09/30/" &  Dropdown1.SelectedValue.ToString
        dtEnd = CDate(tempDate)
        dt = dtStart
        While dt <= dtEnd
            n = Weekday(dt)
            If n = 1 Then
                Dropdown2.Items.Add(dt.ToShortDateString)
            End If
            dt = DateAdd(DateInterval.Day, 1, dt)
        End While
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses
Course of the Month15 days, 3 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question