Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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 27-Nov-12 2:43am
Edited 27-Nov-12 3:20am
digimanus30.8K
v2
Comments
Krunal R at 27-Nov-12 8:23am
   
Can we have your code ?
Mathlab at 27-Nov-12 9:05am
   
Do you have to take the year into account?

1 solution

Rate this: bad
good
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;
       }
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 277
1 Maciej Los 230
2 BillWoodruff 205
3 Sergey Alexandrovich Kryukov 195
4 DamithSL 165
0 OriginalGriff 5,130
1 DamithSL 4,157
2 Maciej Los 3,650
3 Kornfeld Eliyahu Peter 3,460
4 Sergey Alexandrovich Kryukov 2,811


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 27 Nov 2012
Copyright © CodeProject, 1999-2014
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