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
Solved

populating drop downs

Posted on 2006-10-27
5
177 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 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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
Footer for each row on Gridview 2 33
RLDC Reporting in Visual studio 11 30
vb.net 1 month apart 11 35
VB.net capture  result of a SQL query in variables 3 20
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

837 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