Solved

populating drop downs

Posted on 2006-10-27
5
174 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:mwmiller78
  • 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:mwmiller78
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now