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

here i want change month in datetime picker based on month, the total 12 month is available on another ComboBox control, so which month user choose i want to change that month in datetimepicker(windows application)

THANKS
Posted
Comments
ZurdoDev 26-Mar-15 9:59am    
This does not make any sense. Can you update your question and perhaps give a clear example?

you need to get the selected month from your combo to a integer value and set the datetime picker value based on that, for example if you select 3rd month
C#
int monthvalue =3;

dateTimePicker1.Value = new Date(dateTimePicker1.Value.Year, monthvalue, dateTimePicker1.Value.Day);


if you need to change the datetimepicker date, when you select month from from combobox, then you can place above code in the combobox selectedIndexChanged event.

when you bind the month data to combobox, set value member as integer and display member as month name, then you can parse the selected value of combobox to a integer value and set it as datetime picker month as above.
 
Share this answer
 
v2
C#
DateTime monthSelect(int month)
        {
           return DateTime.Now.AddMonths(-DateTime.Now.Month).AddMonths(month+1);
        }

   private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
        {
            dateTimePicker1.Value=monthSelect(comboBox3.SelectedIndex);
        }



You can use this method.
 
Share this answer
 
v2
 
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