Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,

I need to get a list of months in a dropdown which i did.now 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
Updated 27-Nov-12 2:20am
v2
Comments
[no name] 27-Nov-12 8:23am    
Can we have your code ?
[no name] 27-Nov-12 9:05am    
Do you have to take the year into account?

1 solution

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


C#
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;
       }
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900