Click here to Skip to main content
15,904,155 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e)
        {
            monthCalendar1.DateSelected = txtdatein.Text;
           
        }

/* i have typed this code inorder to accept date from my calendar control "monthCalendar1" to my text box "txtdatein" but it generates error. I know the code for asp.net but not for ado.net, which i am expecting to know. */

the error generated is

Error 1 The event 'System.Windows.Forms.MonthCalendar.DateSelected' can only appear on the left hand side of += or -=
Posted
Updated 17-Apr-12 19:21pm
v3
Comments
member60 18-Apr-12 1:38am    
use improve question tag to add details or modify your question
Sergey Alexandrovich Kryukov 18-Apr-12 1:41am    
What is broken? MSDN? Google? Bing?
--SA

i think You want to use the DateTimePicker control in your Windows Forms program.

dateTimePicker1_ValueChanged. This event handler is very useful on the DateTimePicker. Whenever the user changes the DateTime, this event handler is executed.
try this way :
C#
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
    {
        // Set title bar to selected date.
        DateTime result = dateTimePicker1.Value;
        TExtbox1.Text= = result.ToString();
    }
 
Share this answer
 
This control generally shows not a single date, but a range of dates, using the property of MonthCalendar.SelectionRange. You can display the start of this range in you text box, using MonthCalendar.SelectionRange.Start or MonthCalendar.SelectionStart.

Please see:
http://msdn.microsoft.com/en-us/library/system.windows.forms.monthcalendar.selectionrange.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.selectionrange.start.aspx[^].

You need to get a string representation of the time (System.DateTime structure) using System.DateTime.ToString with appropriate format. Please see:
http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^],
http://msdn.microsoft.com/en-us/library/zdtaw1bw.aspx[^],
http://msdn.microsoft.com/en-us/library/az4se3k1.aspx[^],
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx[^].

Last two links reference the MSDN article on how to use date/time format.

—SA
 
Share this answer
 
Comments
VJ Reddy 18-Apr-12 13:01pm    
Good point. 5!
Sergey Alexandrovich Kryukov 18-Apr-12 13:29pm    
Thank you, VJ.
--SA
Hi,
You can write the folowing code in dateTimePicker1_ValueChanged event.

C#
textBox1.Text= = dateTimePicker1.Value.ToString();
 
Share this answer
 
v2

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