Solved

populating drop downs

Posted on 2006-10-27
5
176 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.

831 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