
GcCalendarCellではGcCalendarEditingControl.SelectionModeプロパティを使用して、日付の選択モードを指定できます。日付の選択方法には、1つの日付だけを選択する単一選択と、複数の日付を選択する複数選択の2種類があります。
また、下記に示した選択可能な日付の種類は、
AllowSelectionプロパティで設定します。
- 任意の日付(AllowSellection.AnyDay)
- 営業日(AllowSellection.Workday)
- 休日と休業日(AllowSellection.Holiday)
マウス・キーボードによる日付の選択
日付選択の操作は、目的の日付をマウスでクリックするか、または矢印キーでフォーカス枠を移動し、[Space]キーを押して行います。また、SelectionModeプロパティを"MultiRich"に設定した場合は、Outlookカレンダーと同等の日付選択機能が有効になり、CtrlキーやShiftキーを使った日付選択ができます。
なお、複数選択の場合はGcCalendarEditingControl.MaxSelectionCountプロパティを使用して、選択できる最大日数を設定できます。
Imports GrapeCity.Win.MultiRow
Imports PlusPakCell = GrapeCity.Win.MultiRow.PlusPak
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim GcCalendarCell1 = New PlusPak.GcCalendarCell()
GcCalendarCell1.AllowSelection = GrapeCity.Win.Calendar.AllowSelection.Workday
GcMultiRow1.Template = Template.CreateGridTemplate(New Cell() {GcCalendarCell1})
GcMultiRow1.RowCount = 10
End Sub
Private Sub GcMultiRow1_EditingControlShowing(sender As Object, e As EditingControlShowingEventArgs) Handles GcMultiRow1.EditingControlShowing
Dim gcCalendarEditor As PlusPakCell.GcCalendarEditingControl = TryCast(e.Control, PlusPakCell.GcCalendarEditingControl)
If gcCalendarEditor IsNot Nothing Then
' 複数の日付を選択できるように設定します。
gcCalendarEditor.SelectionMode = GrapeCity.Win.Calendar.SelectionMode.MultiSimple
' 選択できる最大日数を設定します。
gcCalendarEditor.MaxSelectionCount = 5
End If
End Sub
using GrapeCity.Win.MultiRow;
using PlusPakCell = GrapeCity.Win.MultiRow.PlusPak;
private void Form1_Load(object sender, EventArgs e)
{
PlusPakCell.GcCalendarCell gcCalendarCell1 = new PlusPakCell.GcCalendarCell();
gcCalendarCell1.AllowSelection = GrapeCity.Win.Calendar.AllowSelection.Workday;
gcMultiRow1.Template = Template.CreateGridTemplate(new Cell[] { gcCalendarCell1 });
gcMultiRow1.RowCount = 10;
gcMultiRow1.EditingControlShowing += gcMultiRow1_EditingControlShowing;
}
private void gcMultiRow1_EditingControlShowing(object sender, EditingControlShowingEventArgs e)
{
PlusPakCell.GcCalendarEditingControl gcCalendarEditor = (e.Control as PlusPakCell.GcCalendarEditingControl);
if (gcCalendarEditor != null)
{
// 複数の日付を選択できるように設定します。
gcCalendarEditor.SelectionMode = GrapeCity.Win.Calendar.SelectionMode.MultiSimple;
// 選択できる最大日数を設定します。
gcCalendarEditor.MaxSelectionCount = 5;
}
}
コードによる日付の選択
日付はコードで選択することも可能です。この場合、GcCalendarEditingControl.Selectionsプロパティが参照するSelectionCollectionコレクションの次のメソッドのいずれかを使用します。
また、選択した日付を解除するときは、次のいずれかのメソッドを使用します。
Imports GrapeCity.Win.MultiRow
Imports PlusPakCell = GrapeCity.Win.MultiRow.PlusPak
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim GcCalendarCell1 = New PlusPak.GcCalendarCell()
GcCalendarCell1.AllowSelection = GrapeCity.Win.Calendar.AllowSelection.Workday
GcMultiRow1.Template = Template.CreateGridTemplate(New Cell() {GcCalendarCell1})
GcMultiRow1.RowCount = 10
End Sub
Private Sub GcMultiRow1_EditingControlShowing(sender As Object, e As EditingControlShowingEventArgs) Handles GcMultiRow1.EditingControlShowing
Dim gcCalendarEditor As PlusPakCell.GcCalendarEditingControl = TryCast(e.Control, PlusPakCell.GcCalendarEditingControl)
If gcCalendarEditor IsNot Nothing Then
' 複数の日付を選択できるように設定します。
gcCalendarEditor.SelectionMode = GrapeCity.Win.Calendar.SelectionMode.MultiSimple
' 日付を選択します。
gcCalendarEditor.Selections.Add( DateTime.Today.AddDays(2))
End If
End Sub
using GrapeCity.Win.MultiRow;
using PlusPakCell = GrapeCity.Win.MultiRow.PlusPak;
private void Form1_Load(object sender, EventArgs e)
{
PlusPakCell.GcCalendarCell gcCalendarCell1 = new PlusPakCell.GcCalendarCell();
gcCalendarCell1.AllowSelection = GrapeCity.Win.Calendar.AllowSelection.Workday;
gcMultiRow1.Template = Template.CreateGridTemplate(new Cell[] { gcCalendarCell1 });
gcMultiRow1.RowCount = 10;
gcMultiRow1.EditingControlShowing += gcMultiRow1_EditingControlShowing;
}
private void gcMultiRow1_EditingControlShowing(object sender, EditingControlShowingEventArgs e)
{
PlusPakCell.GcCalendarEditingControl gcCalendarEditor = (e.Control as PlusPakCell.GcCalendarEditingControl);
if (gcCalendarEditor != null)
{
// 複数の日付を選択できるように設定します。
gcCalendarEditor.SelectionMode = GrapeCity.Win.Calendar.SelectionMode.MultiSimple;
// 日付を選択します。
gcCalendarEditor.Selections.Add( DateTime.Today.AddDays(2));
}
}
選択された日付の取得
選択された日付は、選択モードの違いによって2つのプロパティを使い分けて取得します。GcCalendarEditingControl.SelectedDateプロパティは、単一選択された日付の取得に使用し、GcCalendarEditingControl.Selectionsプロパティは、複数選択された日付の取得に使用します。
複数選択された日付は、Selectionsプロパティが参照するSelectionCollectionコレクションに格納されます。コレクションの要素である日付にアクセスするには、SelectionCollectionコレクションのItemプロパティまたはインデクサを使用します。
クリックイベントによる日付の取得
カレンダー上の日付をクリック、もしくはダブルクリックした際に発生するGcCalendarEditingControl.ClickDateイベントやGcCalendarEditingControl.DoubleClickDateイベントの引数からクリック操作によって選択された日付の取得が可能です。各イベントのClickDateEventArgs引数にあるDateプロパティから日付を参照することができます。
座標による日付の取得
GcCalendarEditingControl.MouseMoveイベント内で取得したカレンダー上の座標から、日付を取得することが可能です。この場合は、GcCalendarEditingControl.DateFromPointメソッドを使用します。また、その曜日もGcCalendarEditingControl.DayOfWeekFromPointメソッドで取得できます。
表示されている日付の取得
GcCalendarEditingControl.GetDatesInViewメソッドは、現在表示されているカレンダーのすべての日付を取得するときに使用します。また取得する日付の種類は、PickDays引数で指定可能です。
フォーカスを持つ日付の取得
フォーカスを持っている日付は、GcCalendarEditingControl.FocusDateプロパティで取得および設定が可能です。
次のコードでは、GcMultiRow.EditingControlShowingイベントを使用して上記のそれぞれの方法で日付を取得します。
Imports GrapeCity.Win.MultiRow
Imports PlusPakCell = GrapeCity.Win.MultiRow.PlusPak
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim GcCalendarCell1 = New PlusPak.GcCalendarCell()
GcCalendarCell1.AllowSelection = GrapeCity.Win.Calendar.AllowSelection.Workday
GcMultiRow1.Template = Template.CreateGridTemplate(New Cell() {GcCalendarCell1})
GcMultiRow1.RowCount = 10
End Sub
Private Sub GcMultiRow1_EditingControlShowing(sender As Object, e As EditingControlShowingEventArgs) Handles GcMultiRow1.EditingControlShowing
Dim gcCalendarEditor As PlusPakCell.GcCalendarEditingControl = TryCast(e.Control, PlusPakCell.GcCalendarEditingControl)
If gcCalendarEditor IsNot Nothing Then
' 表示されている日付を取得します。
Dim _date As DateTime() = gcCalendarEditor.GetDatesInView()
Console.WriteLine("表示されている最初の日付:{0}", _date(0))
' フォーカスを持つ日付を取得します。
Console.WriteLine("フォーカスを持つ日付の日付:{0}", gcCalendarEditor.FocusDate)
' イベントの設定をします。
RemoveHandler gcCalendarEditor.ClickDate, AddressOf gcCalendarEditor_ClickDate
AddHandler gcCalendarEditor.ClickDate, AddressOf gcCalendarEditor_ClickDate
RemoveHandler gcCalendarEditor.MouseMove, AddressOf gcCalendarEditor_MouseMove
AddHandler gcCalendarEditor.MouseMove, AddressOf gcCalendarEditor_MouseMove
End If
End Sub
Private Sub gcCalendarEditor_ClickDate(sender As Object, e As GrapeCity.Win.Calendar.ClickDateEventArgs)
' クリックによる日付を取得します。
Console.WriteLine("クリックした日付:{0}", e.Date)
End Sub
Private Sub gcCalendarEditor_MouseMove(sender As Object, e As MouseEventArgs)
Dim gcCalendarEditor As PlusPakCell.GcCalendarEditingControl = DirectCast(sender, PlusPakCell.GcCalendarEditingControl)
' 座標による日付を取得します。
Console.WriteLine("マウス座標の日付:{0} 曜日:{1}", _
gcCalendarEditor.DateFromPoint(e.X, e.Y), gcCalendarEditor.DayOfWeekFromPoint(e.X, e.Y))
End Sub
using GrapeCity.Win.MultiRow;
using PlusPakCell = GrapeCity.Win.MultiRow.PlusPak;
private void Form1_Load(object sender, EventArgs e)
{
PlusPakCell.GcCalendarCell gcCalendarCell1 = new PlusPakCell.GcCalendarCell();
gcCalendarCell1.AllowSelection = GrapeCity.Win.Calendar.AllowSelection.Workday;
gcMultiRow1.Template = Template.CreateGridTemplate(new Cell[] { gcCalendarCell1 });
gcMultiRow1.RowCount = 10;
gcMultiRow1.EditingControlShowing += gcMultiRow1_EditingControlShowing;
}
private void gcMultiRow1_EditingControlShowing(object sender, EditingControlShowingEventArgs e)
{
PlusPakCell.GcCalendarEditingControl gcCalendarEditor = (e.Control as PlusPakCell.GcCalendarEditingControl);
if (gcCalendarEditor != null)
{
// 表示されている日付を取得します。
DateTime[] _date = gcCalendarEditor.GetDatesInView();
Console.WriteLine("表示されている最初の日付:{0}", _date[0]);
// フォーカスを持つ日付を取得します。
Console.WriteLine("フォーカスを持つ日付の日付:{0}", gcCalendarEditor.FocusDate);
// イベントの設定をします。
gcCalendarEditor.ClickDate -= gcCalendarEditor_ClickDate;
gcCalendarEditor.ClickDate += gcCalendarEditor_ClickDate;
gcCalendarEditor.MouseMove -= gcCalendarEditor_MouseMove;
gcCalendarEditor.MouseMove += gcCalendarEditor_MouseMove;
}
}
private void gcCalendarEditor_ClickDate(object sender, GrapeCity.Win.Calendar.ClickDateEventArgs e)
{
// クリックによる日付を取得します。
Console.WriteLine("クリックした日付:{0}", e.Date);
}
private void gcCalendarEditor_MouseMove(object sender, MouseEventArgs e)
{
PlusPakCell.GcCalendarEditingControl gcCalendarEditor = (PlusPakCell.GcCalendarEditingControl)sender;
// 座標による日付を取得します。
Console.WriteLine("マウス座標の日付:{0} 曜日:{1}",
gcCalendarEditor.DateFromPoint(e.X, e.Y), gcCalendarEditor.DayOfWeekFromPoint(e.X, e.Y));
}