PowerTools CalendarGrid for Windows Forms 1.0J
週番号

週番号は日付書式を設定することで表示できますが、週番号は週単位で表示するため、カレンダーの表示形式によって作業手順が異なります。

ここでは、カレンダーの表示形式ごとに週番号を表示するためのコーディングを紹介します。


日付書式の設定

日付書式に週番号を設定するには、DateFormatTypeプロパティにCalendarGrid、DateFormatプロパティに{WeekNumber}を設定します。

Imports GrapeCity.Win.CalendarGrid

Dim template As New CalendarTemplate()
template.ColumnHeader.RowCount = 1
template.ColumnCount = 1
template.RowCount = 1

' 行ヘッダに週番号を設定
template.RowHeader.Rows(0).Cells(0).DateFormatType = CalendarDateFormatType.CalendarGrid
template.RowHeader.Rows(0).Cells(0).DateFormat = "{WeekNumber}"

GcCalendarGrid1.Template = template
using GrapeCity.Win.CalendarGrid;

var template = new CalendarTemplate();
template.ColumnHeader.RowCount = 1;
template.RowHeaderColumnCount = 1;
template.RowCount = 1;

// 行ヘッダに週番号を設定
template.RowHeader.Rows[0].Cells[0].DateFormatType = CalendarDateFormatType.CalendarGrid;
template.RowHeader.Rows[0].Cells[0].DateFormat = "{WeekNumber}";

gcCalendarGrid1.Template = template;


月スタイルに週番号を表示する

月スタイルでは、1週間の日付が常に1行として表示されるので、行ヘッダセクションのセルを使用すると週番号が適切に表示されます。

Imports GrapeCity.Win.CalendarGrid

' 小さめのテンプレートを作成
Dim template As New CalendarTemplate()
template.ColumnHeader.RowCount = 1
template.ColumnHeader.Rows(0).Cells(0).DateFormat = "{ShortestDayOfWeek}"
template.ColumnHeader.Rows(0).Cells(0).AutoMergeMode = AutoMergeMode.Horizontal
template.ColumnHeader.Rows(0).Cells(0).DateFormatType = CalendarDateFormatType.CalendarGrid
template.ColumnHeader.Rows(0).Cells(0).CellStyle.Alignment = CalendarGridContentAlignment.MiddleCenter
template.ColumnHeader.Rows(0).Cells(0).CellStyleName = "defaultStyle"
template.ColumnCount = 1
template.RowCount = 1
template.Content.Rows(0).Cells(0).DateFormat = "%d"
template.Content.Rows(0).Cells(0).DateFormatType = CalendarDateFormatType.DotNet
template.Content.Rows(0).Cells(0).CellStyle.Alignment = CalendarGridContentAlignment.MiddleCenter
template.Content.Rows(0).Cells(0).CellStyleName = "defaultStyle"
template.Content.Rows(0).Height = 30
template.Content.Columns(0).Width = 40

' 週番号を行ヘッダに設定
template.RowHeaderColumnCount = 1
template.RowHeader.Columns(0).Width = 40
template.RowHeader.Rows(0).Cells(0).DateFormatType = CalendarDateFormatType.CalendarGrid
template.RowHeader.Rows(0).Cells(0).DateFormat = "{WeekNumber}"

GcCalendarGrid1.Template = template

' カレンダー表示形式に月スタイルのを設定
GcCalendarGrid1.CalendarView = New CalendarMonthView()
using GrapeCity.Win.CalendarGrid;

// 小さめのテンプレートを作成
var template = new CalendarTemplate();
template.ColumnHeader.RowCount = 1;
template.ColumnHeader.Rows[0].Cells[0].DateFormat = "{ShortestDayOfWeek}";
template.ColumnHeader.Rows[0].Cells[0].AutoMergeMode = AutoMergeMode.Horizontal;
template.ColumnHeader.Rows[0].Cells[0].DateFormatType = CalendarDateFormatType.CalendarGrid;
template.ColumnHeader.Rows[0].Cells[0].CellStyle.Alignment = CalendarGridContentAlignment.MiddleCenter;
template.ColumnHeader.Rows[0].Cells[0].CellStyleName = "defaultStyle";
template.ColumnCount = 1;
template.RowCount = 1;
template.Content.Rows[0].Cells[0].DateFormat = "%d";
template.Content.Rows[0].Cells[0].DateFormatType = CalendarDateFormatType.DotNet;
template.Content.Rows[0].Cells[0].CellStyle.Alignment = CalendarGridContentAlignment.MiddleCenter;
template.Content.Rows[0].Cells[0].CellStyleName = "defaultStyle";
template.Content.Rows[0].Height = 30;
template.Content.Columns[0].Width = 40;

// 週番号を行ヘッダに設定
template.RowHeaderColumnCount = 1;
template.RowHeader.Columns[0].Width = 40;
template.RowHeader.Rows[0].Cells[0].DateFormatType = CalendarDateFormatType.CalendarGrid;
template.RowHeader.Rows[0].Cells[0].DateFormat = "{WeekNumber}";

gcCalendarGrid1.Template = template;

// カレンダー表示形式に月スタイルのを設定
gcCalendarGrid1.CalendarView = new CalendarMonthView();


週スタイルに週番号を表示する

週スタイルは、月スタイルと同じように1週間の日付が常に1行として表示されるので、行ヘッダセクションのセルを使用すると週番号が適切に表示されます。

Imports GrapeCity.Win.CalendarGrid

' 小さめのテンプレートを作成
Dim template As New CalendarTemplate()
template.ColumnHeader.RowCount = 1
template.ColumnHeader.Rows(0).Cells(0).DateFormat = "{ShortestDayOfWeek}"
template.ColumnHeader.Rows(0).Cells(0).AutoMergeMode = AutoMergeMode.Horizontal
template.ColumnHeader.Rows(0).Cells(0).DateFormatType = CalendarDateFormatType.CalendarGrid
template.ColumnHeader.Rows(0).Cells(0).CellStyle.Alignment = CalendarGridContentAlignment.MiddleCenter
template.ColumnHeader.Rows(0).Cells(0).CellStyleName = "defaultStyle"
template.ColumnCount = 1
template.RowCount = 1
template.Content.Rows(0).Cells(0).DateFormat = "%d"
template.Content.Rows(0).Cells(0).DateFormatType = CalendarDateFormatType.DotNet
template.Content.Rows(0).Cells(0).CellStyle.Alignment = CalendarGridContentAlignment.MiddleCenter
template.Content.Rows(0).Cells(0).CellStyleName = "defaultStyle"
template.Content.Rows(0).Height = 30
template.Content.Columns(0).Width = 40

' 週番号を行ヘッダに設定
template.RowHeaderColumnCount = 1
template.RowHeader.Columns(0).Width = 40
template.RowHeader.Rows(0).Cells(0).DateFormatType = CalendarDateFormatType.CalendarGrid
template.RowHeader.Rows(0).Cells(0).DateFormat = "{WeekNumber}"

GcCalendarGrid1.Template = template

' カレンダー表示形式に週スタイルのを設定
GcCalendarGrid1.CalendarView = New CalendarWeekView()
using GrapeCity.Win.CalendarGrid;

// 小さめのテンプレートを作成
var template = new CalendarTemplate();
template.ColumnHeader.RowCount = 1;
template.ColumnHeader.Rows[0].Cells[0].DateFormat = "{ShortestDayOfWeek}";
template.ColumnHeader.Rows[0].Cells[0].AutoMergeMode = AutoMergeMode.Horizontal;
template.ColumnHeader.Rows[0].Cells[0].DateFormatType = CalendarDateFormatType.CalendarGrid;
template.ColumnHeader.Rows[0].Cells[0].CellStyle.Alignment = CalendarGridContentAlignment.MiddleCenter;
template.ColumnHeader.Rows[0].Cells[0].CellStyleName = "defaultStyle";
template.ColumnCount = 1;
template.RowCount = 1;
template.Content.Rows[0].Cells[0].DateFormat = "%d";
template.Content.Rows[0].Cells[0].DateFormatType = CalendarDateFormatType.DotNet;
template.Content.Rows[0].Cells[0].CellStyle.Alignment = CalendarGridContentAlignment.MiddleCenter;
template.Content.Rows[0].Cells[0].CellStyleName = "defaultStyle";
template.Content.Rows[0].Height = 30;
template.Content.Columns[0].Width = 40;

// 週番号を行ヘッダに設定
template.RowHeaderColumnCount = 1;
template.RowHeader.Columns[0].Width = 40;
template.RowHeader.Rows[0].Cells[0].DateFormatType = CalendarDateFormatType.CalendarGrid;
template.RowHeader.Rows[0].Cells[0].DateFormat = "{WeekNumber}";

gcCalendarGrid1.Template = template;

// カレンダー表示形式に週スタイルのを設定
gcCalendarGrid1.CalendarView = new CalendarWeekView();


複数列スタイルに週番号を表示する

複数列スタイルでは、コンテンツセクションのセルにを使用すると週番号が適切に表示されます。 また、複数列スタイルは、日付の表示方向を垂直方向または水平方向に設定できるので、それぞれの表示方向にあわせて週番号を表示する位置を指定する必要があります。

次のコードでは、日付の表示方向を垂直方向にして、週番号のセルを自動結合します。

Imports GrapeCity.Win.CalendarGrid

Dim template As New CalendarTemplate()
template.RowCount = 1
template.ColumnCount = 2
template.RowHeader.ColumnCount = 0
template.ColumnHeader.Columns(0).Width = 30
template.ColumnHeader.Columns(1).Width = 60
template.ColumnHeader.Rows(0).Cells(0).Value = "週番号"
template.ColumnHeader.Rows(0).Cells(1).Value = "日付"

' 週番号の設定
template.Content.Rows(0).Cells(0).DateFormatType = CalendarDateFormatType.CalendarGrid
template.Content.Rows(0).Cells(0).DateFormat = "{WeekNumber}"
template.Content.Rows(0).Cells(0).AutoMergeMode = AutoMergeMode.Vertical

template.Content.Rows(0).Cells(1).DateFormat = "{MonthDay}"
template.Content.Rows(0).Cells(1).CellStyleName = "defaultStyle"
GcCalendarGrid1.Template = template

' 複数列スタイルの設定
Dim monthMultiColumnView As New CalendarMonthMultiColumnView()
monthMultiColumnView.Orientation = Orientation.Vertical
monthMultiColumnView.ColumnBreaks = New Integer() {10, 20}

GcCalendarGrid1.CalendarView = monthMultiColumnView
using GrapeCity.Win.CalendarGrid;

var template = new CalendarTemplate();
template.RowCount = 1;
template.ColumnCount = 2;
template.RowHeader.ColumnCount = 0;
template.ColumnHeader.Columns[0].Width = 30;
template.ColumnHeader.Columns[1].Width = 60;
template.ColumnHeader.Rows[0].Cells[0].Value = "週番号";
template.ColumnHeader.Rows[0].Cells[1].Value = "日付";

// 週番号の設定
template.Content.Rows[0].Cells[0].DateFormatType = CalendarDateFormatType.CalendarGrid;
template.Content.Rows[0].Cells[0].DateFormat = "{WeekNumber}";
template.Content.Rows[0].Cells[0].AutoMergeMode = AutoMergeMode.Vertical;

template.Content.Rows[0].Cells[1].DateFormat = "{MonthDay}";
template.Content.Rows[0].Cells[1].CellStyleName = "defaultStyle";
gcCalendarGrid1.Template = template;

// 複数列スタイルの設定
var monthMultiColumnView = new CalendarMonthMultiColumnView();
monthMultiColumnView.Orientation = Orientation.Vertical;
monthMultiColumnView.ColumnBreaks = new int[] { 10, 20};

gcCalendarGrid1.CalendarView = monthMultiColumnView;


リストビュースタイルに週番号を表示する

リストビュースタイルは日付の表示方向を垂直方向または水平方向に設定できるので、それぞれの表示方向にあわせて週番号を表示する位置を指定する必要があります。
日付の表示方向が垂直方向の場合は行ヘッダセクションのセル、水平方向の場合は列ヘッダセクションのセルを使用すると週番号が適切に表示されます。

次のコードでは、日付の表示方向を水平方向にして、週番号のセルを自動結合します。

Imports GrapeCity.Win.CalendarGrid

Dim template As New CalendarTemplate()
template.ColumnHeaderRowCount = 4
template.ColumnCount = 1
template.RowCount = 3
template.CornerHeader.Rows(0).Cells(0).RowSpan = 4

template.ColumnHeader.Rows(0).Cells(0).DateFormat = "{YearMonth}"
template.ColumnHeader.Rows(0).Cells(0).AutoMergeMode = AutoMergeMode.Horizontal
template.ColumnHeader.Rows(1).Cells(0).DateFormatType = CalendarDateFormatType.CalendarGrid

' 週番号の設定
template.ColumnHeader.Rows(1).Cells(0).DateFormat = "{WeekNumber}"
template.ColumnHeader.Rows(1).Cells(0).AutoMergeMode = AutoMergeMode.Horizontal

template.ColumnHeader.Rows(2).Cells(0).DateFormat = "{Day}"
template.ColumnHeader.Rows(2).Cells(0).CellStyleName = "defaultStyle"
template.ColumnHeader.Rows(3).Cells(0).DateFormat = "{ShortestDayOfWeek}"
template.ColumnHeader.Rows(3).Cells(0).CellStyleName = "defaultStyle"
template.ColumnHeader.Columns(0).Width = 30

GcCalendarGrid1.Template = template

' リストビュースタイルの設定
Dim listView As New CalendarListView()
listView.Orientation = Orientation.Horizontal
listView.DayCount = 14
GcCalendarGrid1.CalendarView = listView
using GrapeCity.Win.CalendarGrid;

var template = new CalendarTemplate();
template.ColumnHeaderRowCount = 4;
template.ColumnCount = 1;
template.RowCount = 3;
template.CornerHeader.Rows[0].Cells[0].RowSpan = 4;

template.ColumnHeader.Rows[0].Cells[0].DateFormat = "{YearMonth}";
template.ColumnHeader.Rows[0].Cells[0].AutoMergeMode = AutoMergeMode.Horizontal;
template.ColumnHeader.Rows[1].Cells[0].DateFormatType = CalendarDateFormatType.CalendarGrid;

// 週番号の設定
template.ColumnHeader.Rows[1].Cells[0].DateFormat = "{WeekNumber}";
template.ColumnHeader.Rows[1].Cells[0].AutoMergeMode = AutoMergeMode.Horizontal;

template.ColumnHeader.Rows[2].Cells[0].DateFormat = "{Day}";
template.ColumnHeader.Rows[2].Cells[0].CellStyleName = "defaultStyle";
template.ColumnHeader.Rows[3].Cells[0].DateFormat = "{ShortestDayOfWeek}";
template.ColumnHeader.Rows[3].Cells[0].CellStyleName = "defaultStyle";
template.ColumnHeader.Columns[0].Width = 30;

gcCalendarGrid1.Template = template;

// リストビュースタイルの設定
var listView = new CalendarListView();
listView.Orientation = Orientation.Horizontal;
listView.DayCount = 14;
gcCalendarGrid1.CalendarView = listView;
参照

 

 


© 2014 GrapeCity inc. All rights reserved.