PowerTools CalendarGrid for Windows Forms 1.0J
日付の選択

CalendarGridで任意の日付を選択するには、その日付をクリックするかキーボードのカーソルキー(矢印キー)を使ってセルのフォーカスを移動します。複数の日付を選択するには、マウスで複数の日付をドラッグするか、キーボードでShiftキーを押下したままカーソルキーを使ってセルのフォーカスを移動します。


選択の単位

既定ではCalendarGridではセル単位で選択操作が行われます。日付単位で選択するにはGcCalendarGrid.SelectionUnitプロパティをDateに変更します。

GcCalendarGrid1.SelectionUnit = GrapeCity.Win.CalendarGrid.SelectionUnit.Date
gcCalendarGrid1.SelectionUnit = GrapeCity.Win.CalendarGrid.SelectionUnit.Date;                            


選択された日付の取得

CalendarGrid上で選択された日付は、GcCalendarGrid.SelectedDatesプロパティで参照できます。セルの場合はGcCalendarGrid.SelectedCellsプロパティです。

Imports GrapeCity.Win.CalendarGrid

GcCalendarGrid1.AddSelection(New DateTime(2014, 1, 1))
GcCalendarGrid1.AddSelection(DateTime.Today)

For Each item As DateTime In GcCalendarGrid1.SelectedDates
    Console.WriteLine(item.ToString())
Next

For Each item As CalendarCellPosition In GcCalendarGrid1.SelectedCells
    Console.WriteLine(item.ToString())
Next
gcCalendarGrid1.AddSelection(new DateTime(2014, 1, 1));
gcCalendarGrid1.AddSelection(DateTime.Today);

foreach (var item in gcCalendarGrid1.SelectedDates)
{
    Console.WriteLine(item.ToString());
}

foreach (var item in gcCalendarGrid1.SelectedCells)
{
    Console.WriteLine(item.ToString());
}


コードによる日付選択

コーディングによって日付を選択するには、GcCalendarGrid.AddSelectionメソッドを使用します。

Dim today As DateTime = DateTime.Today
GcCalendarGrid1.AddSelection(today)
var today = DateTime.Today;
gcCalendarGrid1.AddSelection(today);

日付の選択を解除するには、GcCalendarGrid.RemoveSelectionメソッドを使用します。

Dim today As DateTime = DateTime.Today
GcCalendarGrid1.AddSelection(today.AddDays(-1))
GcCalendarGrid1.AddSelection(today)
GcCalendarGrid1.AddSelection(today.AddDays(1))

GcCalendarGrid1.RemoveSelection(today)
var today = DateTime.Today;
gcCalendarGrid1.AddSelection(today.AddDays(-1));
gcCalendarGrid1.AddSelection(today);
gcCalendarGrid1.AddSelection(today.AddDays(1));

gcCalendarGrid1.RemoveSelection(today);

画面に表示されているすべての日を選択するには、CalendarGridActions.SelectAll.Executeメソッドを使用します。

GrapeCity.Win.CalendarGrid.CalendarGridActions.SelectAll.Execute(GcCalendarGrid1)
GrapeCity.Win.CalendarGrid.CalendarGridActions.SelectAll.Execute(gcCalendarGrid1);


選択時のイベント

選択範囲が変更された時、GcCalendarGrid.SelectionChangedイベントが発生します。

Private Sub GcCalendarGrid1_SelectionChanged(sender As Object, e As EventArgs) Handles GcCalendarGrid1.SelectionChanged
    Console.WriteLine("SelectionChanged")
End Sub
private void Form1_Load(object sender, EventArgs e)
{
    gcCalendarGrid1.SelectionChanged += gcCalendarGrid1_SelectionChanged;
}

private void gcCalendarGrid1_SelectionChanged(object sender, EventArgs e)
{
    Console.WriteLine("SelectionChanged");
}


選択の禁止

日付またはセルの選択を禁止する機能はありません。


選択とスクロール

CalendarGridでは、ページスクロールの操作方法によって選択されたセルの保持状態が異なります。

選択状態が解除される操作

タイトルヘッダまたはタイトルフッタに配置したタイトルボタンを使用してページスクロールを行うと、既存の選択は解除されます。たとえば、月カレンダーで今月の日をいくつか選択したあと、先月または翌月にページスクロールすると今月で選択した日の選択は自動的に解除されます。

選択状態が保持される操作

次の操作でページスクロールをした場合は、既存の選択は保持されます。


参照

 

 


© 2014 GrapeCity inc. All rights reserved.