C# and Month Calendar, selecting multiple dates - c#

I am making a program that will help people "book" orders for a department in C#. They need to be able to choose multiple dates in different months.
I would prefer to have it so they can click a date, and then shift click another one to select all dates between those two, and control clicking as well, to do single selection/deselection. They have to be able to move between months while still retaining all the dates they clicked for the previous month, this way they can overview the dates they've selected to make it 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?

You can make it work by detecting clicks on dates and then add or remove the clicked date from the bolded dates. Implement the MonthCalendar's 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();
}
}
Just one problem with this, it flickers like a cheap motel. No fix for that.

The WinForms MonthCalendar supports selection of a Range, from Start to End but not the (de)selection of individual dates with Ctrl. So it seems it does not meet your requirements.
Just a quick note: If you resize the MonthCalendar it will show more months. Together with nobugz' answer that might give you a working solution.

Assuming that you are using WPF...
I would recommend that you create a simple ListBox and bind the ItemsSource property to the Calendar's SelectedDates property. As the user selects and deselects days from the Calendar, they will be added to or removed from the list.
In addition, you could create a DateSpan class and a ValueConverter to group dates in a series into your DateSpan class. You could then apply the converter to the SelectedDates property so that when the user uses Shift-Select, they will see a date span rather than a bunch of dates (assuming that's a bad thing). The logic wouldn't be too complex.
There are plenty of third-party tools out there, but no matter which control you use the core problem will remain: you want the user to be aware of all selected items, but you don't want to show every single month that contains a selected day at the same time. The best answer I can think of would be a list.

Related

Change style for a list of dates in telerik:radcalendar

I'm working on a WPF application and trying to highlight specific dates in a radcalendar, dates that are calculated in my ViewModel class. These highlighted dates would show the user that he/she has upcoming tasks on those dates. I saw that the best (or maybe only) way for that is to implement a StyleSelector, but I'm not sure how to pass the list of dates from my ViewModel class to the StyleSelector class. Could you give me advice? Thanks a lot in advance!

Selection in Date Control

Now, I am working with asp.net , C# and I have made custom controls . In my custom controls especially in Date control, I want to select only month and day part in OnFocus Event.
Right Now, I have wrote
control.select();
then , as usual, the text of the control(2012/08/04) will be selected.
But now I want to give selection only on the part of the month and day(08/04). I am searching many ways to do it. But I haven't got any ways until now. So I would like to know that Can I give a selection on only month and day part(08/24) of a Date Control.
With regards

custom control for large calendar

I'm starting from square one in trying to create a large calendar control. Most likely to take up the whole screen or something. It doesn't need to complex, just navigate to dates and display a line of text on specific days.
From researching this, sounds like I need to create my own custom control, which I have no idea how to do, moreover, how to achieve my objective.
Any insight?
Just finished a similar project here, you'll want to use DataGridView as your control first of all.
Then create functions to control the population of data based on what month/year it is, including extraneous variables like leap year, etc.
So for a start, functions like:
UpdateDaysInMonth(): Determine how many days for Jan,Feb,Mar, etc
UpdateMonth(): Did the user click next month or previous month?
UpdateColumns():
This will be based on your preference, my calendar had days 1-31 all the way across,
but if you're looking for a more traditional looking calendar it would be setup differently. For the days Sun-Sat, use the HeaderText for columns.
Once you have all the base data for what timeframe you're viewing, you can draw out the DataGridView.
Hope this helps, let me know if you have any more questions, and good luck!

How to add a custom display mode to calendar

Is there a way to add a new custom Display Mode to the WPF Calendar control nad how can it be done?
First, I want to describe my problem more in detail.
In my application I need a date (and time) picker in one control to select first a single date and then the time for this date.
The control (as it is) has three display modes which are Decade (showing 12 Years), Month (showing the 12 months of the selected year) and Days (showing the days of the selected month).
What I want to do is, adding another display mode "Hours" which then will show the 24 hours of the selected day.
So there are many problems.
How to add this view?
How to avoid closing the popup after selecting a date? -> it should switch to hours instead and close after selecting the hour
How to add the arrows in the last view to show 12 hours and the halfs on page one of the hours view
How to bind all this to the underlying datetime object which I am interested in at most because it contains what the user selected ;-)
Hope the problem is clear. If there is no direct way to add a view to existing Calendar control than any idea how to solve this would be appreciated.
You could try the Extended WPF toolkit, if you are looking for a out-of-the-box solution. It does not do exactly what you are describing, but it does allow you to select a time in addition to a date.
But if it's not enough, I am pretty sure you will have to make a completely new component. In most cases, a restyling of a component is sufficient to add new features, but in this case, you would most likely have to rewrite it from scratch.
As a workaround, we made a separate hour selection component, which were displayed on the side of the calendar. It's simpler than to rewrite the whole thing anew.

Implementing a multi-state planner

I've been asked to develop a system wherein employees can mark on a form their availability on a given day of the week - for instance an employee could mark themselves as available on a given time on a given week, and unavailable on some other time. It looks a little like this:
http://img697.imageshack.us/img697/842/mvcb.jpg
Currently this works by rendering checkboxes within the table, picking up click events in each cell and marking the checkbox and hence the cell appropriately. I'm using the JQuery "click n drag checkbox" plugin from here. However, I've been informed that there could well be more than two states for a given cell (for instance available, unavailable, available in a given circumstance), in which case binding to a checkboxes checked value isnt going to be a lot of help.
I've never used javascript or asp.net before and am unsure as to the best way to approach this problem. Ideally I could stick a data structure behind each cell which I could update to a certain state and then get my cell colour by binding to this - however I'm at something as a loss as how to best achieve this.
Add a click event to the cell - e.g. click on the cell. Each click could then change the status of the cell. This status could then be store via ajax or using a submit button like on a form. Each cell could relate to a hidden form field which is where you status could be kept.
Maybe take some inspiration from google calendar. There you can select a timespan in the month view by click-dragging a range of days. I guess thats a faster way of entering longer timespans. (Like the lower part of the dragon)

Categories

Resources