C # calendar and month by selecting multiple dates

I am making a program that will help people β€œorder” orders for a C # department. They should be able to select multiple dates in different months.

I would prefer to have it so that it can click the date and then move it to another to select all the dates between the two, and also click the control click to make one choice / deselect. They should be able to move between months, while retaining all the dates that they pressed during the previous month, so they can view the dates that they have chosen to make them easier.

What is the best way to do this? Should I use Visual Studio's default month calendar or is there a more flexible one that exists?

+4
source share
3 answers

You can make it work by detecting clicks by dates, and then add or remove the click date from bold dates. Deploy the MonthCalendar MouseDown event:

private void monthCalendar1_MouseDown(object sender, MouseEventArgs e) { MonthCalendar.HitTestInfo info = monthCalendar1.HitTest(e.Location); if (info.HitArea == MonthCalendar.HitArea.Date) { if (monthCalendar1.BoldedDates.Contains(info.Time)) monthCalendar1.RemoveBoldedDate(info.Time); else monthCalendar1.AddBoldedDate(info.Time); monthCalendar1.UpdateBoldedDates(); } } 

Only one problem with this, it flickers like a cheap motel. No fixes for this.

+8
source

WinForms MonthCalendar supports range selection, from start to finish, but not (de) selecting individual dates using Ctrl. It does not seem to meet your requirements.

A simple note: if you change the size in MonthCalendar, it will display more months. Along with the nobugz answer, which can give you a working solution.

+2
source

Assuming you are using WPF ...

I would recommend creating a simple ListBox and binding the ItemsSource property to the Calendar SelectedDates property. Since the user selects and deselects the days from the Calendar, they will be added or removed from the list.

In addition, you can create the DateSpan and ValueConverter classes to group dates in a series into your DateSpan class. You can then apply the converter to the SelectedDates property so that when the user uses Shift-Select, they will see a date range, not a bunch of dates (assuming it's bad). Logic would not be too complicated.

There are many third-party tools, but no matter which control you use, the main problem remains: you want the user to know about all the selected elements, but you do not want to show every month that contains the selected day at the same time. The best answer I can imagine is a list.

0
source

All Articles