Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
Hi all

In my application i have 2 combo box which contains month name like Jan, Feb....Dec

Now i have to check that the starting month should not be greater than ending month

e.g. if user selects Dec in first combo and select Jan in second combo box, then it should give an error.

Please tell me how to do the validation for this.

Thank you..
Posted
Updated 6-Dec-13 18:46pm
v2
Comments
Sergey Alexandrovich Kryukov 7-Dec-13 0:48am    
How do you know that months are from the same year?
—SA
[no name] 7-Dec-13 0:49am    
i have a year combo box also..the user have to select a year for which they will be able to see the chart ...
Sergey Alexandrovich Kryukov 7-Dec-13 0:54am    
I answered your question, but you have accepted one extremely silly answer. Congratulations.
All you need it to compare first and second combo box selected index.
—SA

First, please see my comment to the question.

Add months in natural order, January to December. The indices of item will index the months 0 to 11. Compare selected indices of the two controls.

—SA
 
Share this answer
 
Comments
[no name] 7-Dec-13 1:23am    
Thanks..it worked..
Sergey Alexandrovich Kryukov 7-Dec-13 1:25am    
Sure. You are welcome.
—SA
Hi,

When you bind the combobox with the data you have value feild associate to each record.
You can use this values to validate
 
Share this answer
 
Comments
[no name] 7-Dec-13 0:09am    
Can u please give some example..
I did it by my self.

i converted the combo box month value and compared.

VB
Dim a As Integer = Convert.ToDateTime("01-" & cmbFMonth.Text & "-1900").Month
Dim b As Integer = Convert.ToDateTime("01-" & cmbTMonth.Text & "-1900").Month


Thanks all..
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 7-Dec-13 0:55am    
Have a shame. Not only you have written an extremely silly answer, you even self-accepted it.
—SA
[no name] 7-Dec-13 1:18am    
what is silly here..please tell me..so i can modify..
u posted after then i posted mine..so didn't saw that..sorry about that..
and there is nothing to use such language..i posted which i got the way..
Sergey Alexandrovich Kryukov 7-Dec-13 1:24am    
Nothing to modify, I already answered. This is:
if (cmdFMonth.SelectedIndex > cmdTMonth.SelectedIndex) ...
That's it.
—SA
[no name] 7-Dec-13 1:26am    
see my comment in this question..and also in your answer..
[no name] 7-Dec-13 1:30am    
See Sergey you guys are lots and lots of senior then many of us.
what i posted i don't think it's that much silly the way u reacted.
with all do respect it's some what discouraging.
please don't take me wrong.i m telling which i felt..

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