user1909530
user1909530

Reputation: 11

Unable to put calendar selected date into datetime C#

I am experiencing troubles while creating a form for a greater project of mine. I need the selected date of a calendar to be saved into a datetime variable, however when i try to use:

DateTime valtdatum = calKalender.SelectedDate();

I am faced with syntax errors. I don't know if the SelectedDate-method is ASP.NET exclusive or if it is possible to use it with normal C#, however i do not know of any equivalent to this method.

Am i simply using the wrong method? Is there a namespace that I need to enable?

Regards, Jonathan

Upvotes: 1

Views: 2777

Answers (2)

Habib
Habib

Reputation: 223312

Am i simply using the wrong method? Is there a namespace that I need to enable?

In ASP.Net Calendar.SelectedDate is a property not a method. You can use it like:

DateTime valtdatum = calKalender.SelectedDate;

You need to remove the () since its not a method.

EDIT:

Since in your comments you specified that its a System.Windows.Forms.MonthCalender then you need to do the following to get the Selected Date.

Set the property MaxSelectionCount to 1, so that only a single selection can be made, and then you can use SelectionRange.Start property :

DateTime valtdatum = calKalender.SelectionRange.Start;

Or use SelectionStart property directly.

DateTime valdatum = calKalender.SelectionStart;

Upvotes: 7

Nirmal
Nirmal

Reputation: 1245

DateTime valtdatum = calKalender.SelectedDate;

Will work for you

Upvotes: 2

Related Questions