Solved

populating drop downs

Posted on 2006-10-27
5
178 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 17

Assisted Solution

by:ZeonFlash
ZeonFlash earned 100 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 400 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
vb.net and creating a class 5 31
System.net.Sockets Error 5 40
how to remove error in database 6 36
How can I add google maps in vb.net. 2 21
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

733 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