Hi, i am new to c# and i am trying to develop a form to display the calander which works fine. I am trying to make it so that when the user selects any date from my MonthCalander control, it is then displayed in a messasge box. The trouble i'm having is that it no matter which date i select, it displays by default, todays date(the current todays date). Here is my code snippet:
public partial class newcontractform : Form
{
System.Data.OleDb.OleDbConnection con;
private string projectName;
private DateTime startDate;
public newcontractform()
{
InitializeComponent();
projectName = nametxtbx.Text;
monthCalendar1.MaxSelectionCount = 1;
startDate = monthCalendar1.SelectionStart;
}
private void submitbtn_Click(object sender, EventArgs e)
{
MessageBox.Show("start date is: " + startDate.ToShortDateString());
this.Close();
}
Loading
Madhu KPosted Dec 10, 2010, 6:25 AM
private void submitbtn_Click(object sender, EventArgs e)
{
startDate = monthCalendar1.SelectionStart.ToString();
MessageBox.Show("start date is: " + startDate.ToShortDateString());
this.Close();
}
simon taylorPosted Dec 10, 2010, 6:10 AM
startDate = monthCalendar1.SelectionStart.ToString();
and output it in using, Messagebox.show("date was " + start date);
it simply shows todays date and not the date selected, why? I only ask because i want to understand the reason.
Madhu KPosted Dec 10, 2010, 1:00 AM
private void submitbtn_Click(object sender, EventArgs e)
{
MessageBox.Show("start date is: " + monthCalendar1.SelectionStart.ToString());
this.Close();
}
Gomathi PalaniswamyPosted Dec 9, 2010, 11:41 PM
make your question clear...
The below code display's the selected date..post your code little bit elaborate..
DateTime dt;
private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e)
{
monthCalendar1.MaxSelectionCount = 1;
dt = monthCalendar1.SelectionRange.Start;
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(dt.ToString());
}