Click here to Skip to main content
11,430,708 members (72,295 online)
Click here to Skip to main content

Calendar Planner

, 6 May 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
A control similar to the Outlook Calendar control.

WeekPlanner/Calendar.png

Introduction 

During my job I was in need of a .NET WinForms control which would allow to fetch data from the database and manipulate it like in Outlook Calendar Planner (add, delete, drag items), but with a few differences. Instead of showing the time information in the left side of the control, it was necessary to retrieve and show columnar data from the database. I found some similar controls: A Professional Calendar/Agenda View That You Will Use, Calendar DayView Control, and Day, Week, and Month Calendar Controls, but none of them met my requirements. For commercial components, I didn't want to pay. So I created my own Calendar Planner.

Control Features

The control consists of rows with items and columns in the left side, as you can see from the screenshot below.

WeekPlanner/CalendarRow.png

Each item in a row can be updated individually. You can change the background color, specify text, drag it, change date, etc. In the left side of the calendar you can add columns with some text, it may be used in order to retrieve data from different data sources (for example, from DB or XML file). The component can show date intervals in two modes: daily and weekly. In daily mode, each date shows day name, as in the screenshot above. In weekly mode, the date shows the week number, as in the screenshot below. Control supports rows nesting. For this you can set a row as collapsible. 

WeekPlanner/CalendarRow2.png

Background

In order to manage the behaviour of the control, you can use different properties. Some of them are:

  • CurrentDate: gets/sets calendar date.
  • DatesIntervalMode: possible modes to show date intervals in the header.
  • DayCount: day count to show by the calendar.
  • GridCellHeight: height of each row.
  • HeaderStylemode: possible modes to fill background header.
  • IsAllowedDraggingBetweenRows: allows/disallows item drag/drop between rows.
  • ItemHeight: height of each item.
  • LeftMargin: margin of left column.
  • SelectedRowindex: gets the index of the selected row.
  • SelectedItem: gets the selected item.
  • Rows: list of rows of the calendar.
  • Items: list of items of the row. 
  • Columns: columns in the left side of the control.
  • IsAllowedTreeViewDrawing: Enables\Disables lines drawing like in tree view 

Events:

  • ItemClick: occurs when an item is clicked.
  • ItemDoubleClick: occurs when an item is double-clicked.
  • RowClick: occurs when a row is clicked.
  • RowDoubleClick: occurs when a row is double-clicked.
  • ItemDatesChanged: occurs when an item date range has changed.
  • ItemTextEdited: occurs when an item text is edited.

Using the code

The control doesn't support data binding, so you must write your own logic for rows with items saving and fetching.

Each row of the control, this is the class WeekPlannerRow with different properties (such as BackColor, Name, and others). The calendar consists of a list of rows in the class WeekPlannerRowCollection: List<WeekPlannerRow>.

In turn each row contains a list of items WeekPlannerItemCollection:List<WeekPlannerItem>. An item is the class WeekPlannerItem with some properties: StartDate, EndDate, Subject, BackColor, and others.

Also, each row has columns, and all related methods can be found in the DataColumns class. This class contains an array of classes DataValue with properties like: Name (name of column), Width (width of column), and Text (text for column header). Also, the DataValue class has a list ValueColorCollection : List<weekplanneritem>. The purpose of the ValueColor<weekplanneritem> class is to show text information in a column in different colors.

In order to add columns, you can use this code:

weekPlanner1.Columns.Add("ColumnName1", string.Empty, 150);
weekPlanner1.Columns.Add("ColumnName2", string.Empty, 150);
// 150 is the width of column

Rows adding happens this way:

// creates new instance of the List of Items, which will be added to the row
var itemCollection = new WeekPlannerItemCollection(); 
// creates new instance of item, which will be added to the row's items list
var item = new WeekPlannerItem(); 
item.StartDate = DateTime.Now.AddDays(0); 
item.EndDate = DateTime.Now.AddDays(0); 
item.Subject = "1 date"; 
item.BackColor = Color.YellowGreen; 
// adds item to the list
itemCollection.Add(item); 
// creates new instance of the columns, which will be added to the row
var ColumnRows = new DataColumns(weekPlanner1.Calendar); 
// adds random text to the column ColumnName1,
// which was created in the code snippet above
ColumnRows["ColumnName1"].Data.Add(Guid.NewGuid().ToString().Substring(0, 8)); 
// adds another random text to the column ColumnName1 
ColumnRows["ColumnName1"].Data.Add(Guid.NewGuid().ToString().Substring(0, 8)); 
// adds random text to the column ColumnName2
ColumnRows["ColumnName2"].Data.Add(Guid.NewGuid().ToString().Substring(0, 8)); 
// adds row to the calendar
weekPlanner1.Rows.Add(ColumnRows, itemCollection);

Here is the code for items adding:

// gets calendar rows collection
var rows = weekPlanner1.Rows; 
// finds selected row by index
var row = rows.ElementAt(weekPlanner1.SelectedRowIndex); 
// creates new instance of item, which will
// be added to the row's items list
var item = new WeekPlannerItem(); 
item.StartDate = DateTime.Now.AddDays(0); 
item.EndDate = DateTime.Now.AddDays(0); 
item.Subject = "Example"; 
item.BackColor = Color.YellowGreen; 
// adds item to the row
row.Items.Add(item);

History

  • 09.08.2011
    • Initial release.
  • 20.08.2011
    • Added new events OnItemDatesChanged, OnItemTextEdited.
  • 04.09.2011
    • Added new events OnItemMouseHover, OnItemMouseLeave.
  • 11.10.2011
    • Now each row increases its height individually.  
  • 24.04.2013
    • Added new property IsAllowedTreeViewDrawing, event OnRowLeftColumnClick.  
    • Added new row properties IsVisibleIsExpandedAncestorNameIsCollapsible.   

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Yury Yuhno
Software Developer Axon Cable
Latvia Latvia
No Biography provided

Comments and Discussions

 
QuestionHow to disable moving, editing and resizing the events ? Pin
Murulimadhav128-Jan-15 1:03
memberMurulimadhav128-Jan-15 1:03 
QuestionMessage Removed Pin
Murulimadhav126-Jan-15 22:13
memberMurulimadhav126-Jan-15 22:13 
QuestionMake some item unmovable/unclickable Pin
YAllTaken4-Jun-14 23:37
memberYAllTaken4-Jun-14 23:37 
QuestionMonth View? Pin
RRJP20-Nov-13 22:18
memberRRJP20-Nov-13 22:18 
AnswerRe: Month View? Pin
RRJP20-Nov-13 23:57
memberRRJP20-Nov-13 23:57 
QuestionBackground Color of individual Cells Pin
Member 101956688-Oct-13 6:26
memberMember 101956688-Oct-13 6:26 
QuestionNICE WORK!! Pin
Paulo Lima2-Oct-13 9:36
memberPaulo Lima2-Oct-13 9:36 
Questionload from DB Pin
tony5551-Oct-13 6:02
membertony5551-Oct-13 6:02 
Questionover lapping Pin
tony5551-Oct-13 3:55
membertony5551-Oct-13 3:55 
QuestionHow retrieve column inside text? Pin
Alb7525-Jul-13 5:00
memberAlb7525-Jul-13 5:00 
AnswerRe: How retrieve column inside text? [modified] Pin
RajibXYZ7-Nov-13 21:22
memberRajibXYZ7-Nov-13 21:22 
Questiondragging items Pin
YAllTaken24-Jun-13 1:58
memberYAllTaken24-Jun-13 1:58 
AnswerRe: dragging items Pin
Yury Yuhno25-Jun-13 20:22
memberYury Yuhno25-Jun-13 20:22 
GeneralRe: dragging items [modified] Pin
YAllTaken26-Jun-13 2:45
memberYAllTaken26-Jun-13 2:45 
GeneralRe: dragging items Pin
Yury Yuhno26-Jun-13 23:41
memberYury Yuhno26-Jun-13 23:41 
QuestionNice Work Pin
Member 1010526016-Jun-13 23:21
memberMember 1010526016-Jun-13 23:21 
AnswerRe: Nice Work Pin
Member 1010526019-Jun-13 3:59
memberMember 1010526019-Jun-13 3:59 
AnswerRe: Nice Work Pin
Yury Yuhno26-Jun-13 1:22
memberYury Yuhno26-Jun-13 1:22 
GeneralSuper work Pin
goms3rd8-May-13 1:09
membergoms3rd8-May-13 1:09 
GeneralMy vote of 5 Pin
FernandoUY7-May-13 4:48
memberFernandoUY7-May-13 4:48 
GeneralMy vote of 5 Pin
Renju Vinod29-Apr-13 3:05
memberRenju Vinod29-Apr-13 3:05 
GeneralMy vote of 5 Pin
Daniel Cruz25-Apr-13 10:02
memberDaniel Cruz25-Apr-13 10:02 
GeneralMy vote of 5 Pin
Sudhakar Shinde24-Apr-13 1:59
memberSudhakar Shinde24-Apr-13 1:59 
Questionweekends in different color Pin
theBartman6927-Mar-13 23:25
membertheBartman6927-Mar-13 23:25 
SuggestionRe: weekends in different color Pin
tanguy humblot29-Aug-13 3:59
membertanguy humblot29-Aug-13 3:59 
QuestionVery nice control Pin
Member 831661425-Feb-13 2:59
memberMember 831661425-Feb-13 2:59 
Question10 minute division Pin
pedro_portway14-Oct-12 8:57
memberpedro_portway14-Oct-12 8:57 
GeneralMy vote of 5 Pin
Ian A Stewart4-Sep-12 9:08
memberIan A Stewart4-Sep-12 9:08 
QuestionToolTip into weekplanneritem Pin
tacho4-Sep-12 7:14
membertacho4-Sep-12 7:14 
AnswerRe: ToolTip into weekplanneritem Pin
YAllTaken29-Jul-13 2:13
memberYAllTaken29-Jul-13 2:13 
AnswerRe: ToolTip into weekplanneritem Pin
RajibXYZ1-Nov-13 3:01
memberRajibXYZ1-Nov-13 3:01 
QuestionHelp please : Calendar language ?? Pin
EL HANI Abdelatif15-May-12 12:38
memberEL HANI Abdelatif15-May-12 12:38 
SuggestionRe: Help please : Calendar language ?? Pin
Alain BOURLAND17-Jul-12 3:32
memberAlain BOURLAND17-Jul-12 3:32 
GeneralRe: Help please : Calendar language ?? Pin
EL HANI Abdelatif21-Dec-12 12:43
memberEL HANI Abdelatif21-Dec-12 12:43 
thank you !! it works Smile | :)
QuestionVery Nice Pin
victorbos18-Oct-11 3:52
membervictorbos18-Oct-11 3:52 
GeneralRe: Very Nice Pin
Yury Yuhno18-Oct-11 21:53
memberYury Yuhno18-Oct-11 21:53 
GeneralMy vote of 4 Pin
SledgeHammer0114-Oct-11 12:39
memberSledgeHammer0114-Oct-11 12:39 
QuestionVB Net? Pin
isensa7-Oct-11 10:56
memberisensa7-Oct-11 10:56 
AnswerRe: VB Net? Pin
DavidSullivan12-Oct-11 9:39
memberDavidSullivan12-Oct-11 9:39 
GeneralMy vote of 5 Pin
JanvdK20-Sep-11 9:19
memberJanvdK20-Sep-11 9:19 
GeneralMy vote of 4 Pin
Member 191236720-Sep-11 5:42
memberMember 191236720-Sep-11 5:42 
QuestionSupport for Minutes or Hours? Pin
RheedHamilton19-Sep-11 15:35
memberRheedHamilton19-Sep-11 15:35 
AnswerRe: Support for Minutes or Hours? Pin
Member 1010526016-Jun-13 23:32
memberMember 1010526016-Jun-13 23:32 
GeneralRe: Support for Minutes or Hours? Pin
jibola11-Oct-13 3:31
memberjibola11-Oct-13 3:31 
QuestionNice Article! Pin
Member 45586616-Sep-11 10:48
memberMember 45586616-Sep-11 10:48 
AnswerRe: Nice Article! Pin
knoami19-Oct-11 0:19
memberknoami19-Oct-11 0:19 
QuestionNice Article! Pin
Member 45586616-Sep-11 10:47
memberMember 45586616-Sep-11 10:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150428.2 | Last Updated 6 May 2013
Article Copyright 2011 by Yury Yuhno
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid