Click here to Skip to main content
12,757,627 members (39,293 online)
Rate this:
Please Sign up or sign in to vote.
See more: C#

I need to get a list of months in a dropdown which i what i need is if i selected one month from the dropdown i need another list should contain the selected month's value plus the previous 3 months values .

Eg : if i select nov from dropdown the list should contain nov,oct,sept and aug.

but i select jan then only jan should get populated in the list.

The list should be of type integer which can store Month index.

Can anyone plss help me in doing this...its urgent
Posted 27-Nov-12 2:43am
Updated 27-Nov-12 3:20am
Krunal R 27-Nov-12 8:23am
Can we have your code ?
Mathlab 27-Nov-12 9:05am
Do you have to take the year into account?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Here is some simple code you can modify to get what you need, just mak sure the months in you datasource are sequential.

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
           comboBox2.SelectedIndex = previousMonth(comboBox1.SelectedIndex);
           comboBox3.SelectedIndex = previousMonth(comboBox2.SelectedIndex);
           comboBox4.SelectedIndex = previousMonth(comboBox3.SelectedIndex);

       private int previousMonth(int sIndex)
           if (sIndex == -1) return -1;
           if (sIndex == 0) sIndex = 12;
               return sIndex - 1;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170217.1 | Last Updated 27 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100