0

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:

namespace AddContractUI
{
    public partial class newcontractform : Form
    {
        System.Data.OleDb.OleDbConnection con;

        private string projectName;
        private DateTime startDate;

  public newcontractform()
        {

 InitializeComponent();
             

            monthCalendar1.MaxSelectionCount = 1;

            startDate = monthCalendar1.SelectionStart;

 

        }

        private void submitbtn_Click(object sender, EventArgs e)
        {
            MessageBox.Show("date selected was" + startDate);
            this.Close();
             
        }

// res of code skippet
}

I would be SO greatful for somebody to tell me where i am going wrong please

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by nvidia123
0
private void button2_Click(object sender, EventArgs e)
        {
            DateTime date = monthCalendar1.SelectionStart;
            MessageBox.Show("Selected date was: " + date.ToShortDateString());
        }
0

hi thanks for the help BUT i still keep getting todays date.

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();
             
        }

do you have anymore suggestions?
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.