Reputation: 123
I have a 2d array and if the date selected using the dateTimePicker is a monday I want to set the row index to 1. If the date selected is a tuesday I want to set the row index to 2... I have tried do this using the code below but it doesn't seem to work:
if (dateTimePicker.Value == DateTime.DayOfWeek.Monday)
r = 1;
if (dateTimePicker.Value == DateTime.DayOfWeek.tuesday)
r = 2;
Upvotes: 2
Views: 17222
Reputation: 13106
dateTimePicker.Value
will contain a full DateTime
. You're comparing that against a constant. Try comparing dateTimePicker.Value.DayOfWeek
to the enum
constants.
Upvotes: 0
Reputation: 12815
According to Microsoft's documentation, DateTimePicker.Value
is of type DateTime
.
Take the DayOfWeek
property to get the value you're looking for.
Your statement should look like:
if ( dateTimePicker.Value.DayOfWeek == DayOfWeek.Monday )
...
Upvotes: 3