GcCalendarGridコントロールは、3つのデータ連結モードをサポートしており、用途に合わせて最適なモードを選択できます。
アンバウンド(非連結)モード
アンバウンド モードは、比較的少量のデータを表示するのに適しています。このモードでは、データソースに直接接続せず、すべてのデータをGcCalendarGridコントロール内に保持します。
アンバウンドモードにおけるデータの操作方法は 「データの入力」を参照してください。
バウンドモード
バウンドモードはデータソースに接続し、データソースから読み出したデータを一致する日付のセルに表示します。
バウンドモードの詳細は「データベースとの連結」を参照してください。
仮想モード
仮想モードは大量のデータを高速に扱う場合に適しています。このモードでは、GcCalendarGridコントロールはデータを自動的にコントロールに読み込みません。開発者は、すべてのデータの反映のタイミングをコーディングしてデータの表示を指示します。このモードは、必要最小限のデータのみを保持してパフォーマンスを改善する用途に適しています。
GcCalendarGrid.VirtualModeプロパティがTrueのとき、GcCalendarGridコントロールは仮想モードとして動作します。
仮想モードでは、コントロールにデータが必要になるタイミングでGcCalendarGrid.CellValueNeededイベントが発生します。このタイミングには、スクロールやフォームの再描画が含まれます。次のコードはGcCalendarGrid.CellValueNeededイベントを使用してセルのインデックスを表示します。
Imports GrapeCity.Win.CalendarGrid
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' 仮想モードを設定
GcCalendarGrid1.VirtualMode = True
AddHandler GcCalendarGrid1.CellValueNeeded, AddressOf GcCalendarGrid1_CellValueNeeded
End Sub
Private Sub GcCalendarGrid1_CellValueNeeded(sender As Object, e As CalendarCellValueEventArgs)
e.Value = "(" + e.CellPosition.RowIndex.ToString() + ", " + e.CellPosition.ColumnIndex.ToString() + ")"
End Sub
using GrapeCity.Win.CalendarGrid;
private void Form1_Load(object sender, EventArgs e)
{
// 仮想モードを設定
gcCalendarGrid1.VirtualMode = true;
gcCalendarGrid1.CellValueNeeded += gcCalendarGrid1_CellValueNeeded;
}
private void gcCalendarGrid1_CellValueNeeded(object sender, GrapeCity.Win.CalendarGrid.CalendarCellValueEventArgs e)
{
e.Value = "(" + e.CellPosition.RowIndex.ToString() + ", " + e.CellPosition.ColumnIndex.ToString() + ")";
}
 |
注意 CellValueNeededイベントでセルのValueプロパティを直接参照して値を設定すると処理が正しく実行されません。CellValueNeededイベントでは、EventArgs.Valueを使用して値を設定してください。 |
仮想モードでAppointment型セルの予定範囲を設定する場合は、セルのRowSpan、ColumnSpanプロパティを直接参照して範囲の設定を行います。
Imports GrapeCity.Win.CalendarGrid
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim AppointmentCellType As New CalendarAppointmentCellType()
Dim Template As New CalendarTemplate()
Template.RowCount = 3
Template.RowHeaderColumnCount = 0
Template.ColumnHeader.Rows(0).Cells(0).DateFormat = "{DayOfWeek}"
Template.ColumnHeader.Columns(0).Width = 50
Template.Content.Rows(0).Cells(0).DateFormat = "{MonthDay}"
Template.Content.Rows(0).Cells(0).CellStyleName = "defaultStyle"
Template.Content.Rows(1).Cells(0).Name = "myCell1"
Template.Content.Rows(1).Cells(0).CellType = appointmentCellType.Clone()
Template.Content.Rows(1).Cells(0).CellStyleName = "defaultStyle"
GcCalendarGrid1.Template = Template
' 仮想モードを設定
GcCalendarGrid1.VirtualMode = True
AddHandler GcCalendarGrid1.CellValueNeeded, AddressOf GcCalendarGrid1_CellValueNeeded
End Sub
Private Sub GcCalendarGrid1_CellValueNeeded(sender As Object, e As CalendarCellValueEventArgs)
Dim gcCalendarGrid = DirectCast(sender, GcCalendarGrid)
' EventArgs.Valueを使用してセルの値を設定
e.Value = "(" + e.CellPosition.RowIndex.ToString() + ", " + e.CellPosition.ColumnIndex.ToString() + ")"
If e.CellPosition.Date.DayOfWeek = DayOfWeek.Monday Then
' Appointment型セルの予定範囲は、セルのColumnSpanを直接参照して範設定
gcCalendarGrid.Content(e.CellPosition.Date)(e.CellPosition.RowIndex, e.CellPosition.ColumnIndex).ColumnSpan = 5
End If
End Sub
using GrapeCity.Win.CalendarGrid;
private void Form1_Load(object sender, EventArgs e)
{
var appointmentCellType = new CalendarAppointmentCellType();
var template = new CalendarTemplate();
template.RowCount = 3;
template.RowHeaderColumnCount = 0;
template.ColumnHeader.Rows[0].Cells[0].DateFormat = "{DayOfWeek}";
template.ColumnHeader.Columns[0].Width = 50;
template.Content.Rows[0].Cells[0].DateFormat = "{MonthDay}";
template.Content.Rows[0].Cells[0].CellStyleName = "defaultStyle";
template.Content.Rows[1].Cells[0].Name = "myCell1";
template.Content.Rows[1].Cells[0].CellType = appointmentCellType.Clone();
template.Content.Rows[1].Cells[0].CellStyleName = "defaultStyle";
gcCalendarGrid1.Template = template;
// 仮想モードを設定
gcCalendarGrid1.VirtualMode = true;
gcCalendarGrid1.CellValueNeeded += gcCalendarGrid1_CellValueNeeded;
}
private void gcCalendarGrid1_CellValueNeeded(object sender, GrapeCity.Win.CalendarGrid.CalendarCellValueEventArgs e)
{
var gcCalendarGrid = sender as GcCalendarGrid;
// EventArgs.Valueを使用してセルの値を設定
e.Value = "(" + e.CellPosition.RowIndex.ToString() + ", " + e.CellPosition.ColumnIndex.ToString() + ")";
if (e.CellPosition.Date.DayOfWeek == DayOfWeek.Monday)
{
// Appointment型セルの予定範囲は、セルのColumnSpanを直接参照して範設定
gcCalendarGrid.Content[e.CellPosition.Date][e.CellPosition.RowIndex, e.CellPosition.ColumnIndex].ColumnSpan = 5;
}
}
関連トピック