Jaden Ken
Jaden Ken

Reputation: 33

How to convert days on a calendar when click into a string

Here is my code. I was trying to test the SelectedDate for my program so the user can click on the date and it'll make it into a string. However, when the SelectedDate tag has a red line under it that is indicating that:

'monthCalendar1' does not contain a definition for 'SelectedDate' and no accessible extension method 'SeclectedDate' accepted a first argument of type 'monthCalendar' could be found (are you missing a using directive or an assembly reference?).

private void monthCalendar1_SelectedDate(object sender, DateRangeEventArgs e)
{
    txtDay.Text = monthCalendar1.SelectedDate.ToString("dd");
}

[enter image description here]

Upvotes: 1

Views: 62

Answers (1)

Vijunav Vastivch
Vijunav Vastivch

Reputation: 4191

you can use it like this:

var selectedDate = (DateTime.Parse(e.Start.ToShortDateString())).Day;

or

txtDay.Text = (DateTime.Parse(e.Start.ToShortDateString())).Day.ToString();

Upvotes: 1

Related Questions