今日の日付に移動するには?

文書番号 : 37320     文書種別 : 使用方法     登録日 : 2014/05/28     最終更新日 : 2014/05/28
文書を印刷する
対象製品
CalendarGrid for Windows Forms 1.0J
詳細
今日の日付に移動するには、次の方法があります。
  1. タイトルボタンを使用する
  2. AddSelectionメソッドで今日を選択し、ScrollIntoViewメソッドで今日にスクロールする
  3. CurrentCellPositionプロパティで現在のセルを今日に設定する

1. タイトルボタンを使用する
タイトルヘッダまたはタイトルフッタに配置したタイトルボタンのButtonBehaviorプロパティに” GotoToday”が設定されている場合、このボタンをクリックすると今日に移動します。既定では、タイトルヘッダに「今日へ移動」ボタンが配置されています。

2. AddSelectionメソッドで今日を選択し、ScrollIntoViewメソッドで今日にスクロールする
AddSelectionメソッドは指定した日付を選択します。また、ScrollIntoViewメソッドは指定した日付にカレンダーをスクロールします。

[Visual Basic]
Dim today As DateTime = DateTime.Today
' 現在の選択をクリアします。
GcCalendarGrid1.ClearSelection()
' 今日の日付を選択します。
GcCalendarGrid1.AddSelection(today)
' 今日の日付にスクロールします。
GcCalendarGrid1.ScrollIntoView(today)

[C#]
var today = DateTime.Today;
// 現在の選択をクリアします。
gcCalendarGrid1.ClearSelection();
// 今日の日付を選択します。
gcCalendarGrid1.AddSelection(today);
// 今日の日付にスクロールします。
gcCalendarGrid1.ScrollIntoView(today);

3. CurrentCellPositionプロパティで現在のセルを今日に設定する
CurrentCellPositionプロパティは、現在のセルの位置を設定できるので、今日の日付のどのセルを選択するかを指定できます。CurrentCellPositionプロパティを使用すると、指定した日付にカレンダーがスクロールします。

[Visual Basic]
Dim today As DateTime = DateTime.Today
' 今日の3行1列目のセルに移動します。
GcCalendarGrid1.CurrentCellPosition = New GrapeCity.Win.CalendarGrid.CalendarCellPosition(today, 2, 0)

[C#]
var today = DateTime.Today;
// 今日の3行1列目のセルに移動します。
gcCalendarGrid1.CurrentCellPosition = new GrapeCity.Win.CalendarGrid.CalendarCellPosition(today, 2, 0);
関連情報