ユーザーが
GcCalendarGrid コントロールに独自のデータ管理操作を提供するかどうかを示す値を取得または設定します。
public bool VirtualMode {get; set;}
Public Property VirtualMode As Boolean
プロパティ値
GcCalendarGrid コントロールで、ユーザーが提供したデータ管理操作が使用されるようにする場合は
true。それ以外の場合は
false。既定値は
false です。
次のサンプルコードは、仮想モード機能を使用して GcCalendarGrid にデータを提供する方法を示します。
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Collections.Generic;
using GrapeCity.Win.CalendarGrid;
namespace CalendarGridSampleCode
{
class VirtualModeDemo : Form
{
GcCalendarGrid gcCalendarGrid = new GcCalendarGrid();
private Dictionary<CalendarCellPosition, object> _valueCache = new Dictionary<CalendarCellPosition, object>();
public VirtualModeDemo()
{
gcCalendarGrid.Template = this.CreateTemplate();
gcCalendarGrid.Dock = DockStyle.Fill;
gcCalendarGrid.VirtualMode = true;
gcCalendarGrid.CellValueNeeded += gcCalendarGrid_CellValueNeeded;
gcCalendarGrid.CellValuePushed += gcCalendarGrid_CellValuePushed;
this.Text = "Virtual Mode Demo";
this.Controls.Add(gcCalendarGrid);
}
void gcCalendarGrid_CellValueNeeded(object sender, CalendarCellValueEventArgs e)
{
if (_valueCache.ContainsKey(e.CellPosition))
{
e.Value = _valueCache[e.CellPosition];
}
else
{
e.Value = "Edit Me";
}
}
void gcCalendarGrid_CellValuePushed(object sender, CalendarCellValueEventArgs e)
{
if (_valueCache.ContainsKey(e.CellPosition))
{
//Same the value by your own.
_valueCache[e.CellPosition] = e.Value;
}
else
{
_valueCache.Add(e.CellPosition, e.Value);
//If the value is saved by user, change the back color.
this.gcCalendarGrid[e.CellPosition.Date][e.CellPosition.RowIndex, e.CellPosition.ColumnIndex].CellStyle.BackColor = Color.Lime;
}
}
private CalendarTemplate CreateTemplate()
{
CalendarTemplate calendarTemplate1 = new CalendarTemplate();
GrapeCity.Win.CalendarGrid.CalendarHeaderCellType calendarHeaderCellType1 = new GrapeCity.Win.CalendarGrid.CalendarHeaderCellType();
calendarTemplate1.RowCount = 2;
calendarTemplate1.RowHeaderColumnCount = 0;
calendarTemplate1.ColumnHeader.CellStyleName = "defaultStyle";
calendarHeaderCellType1.SupportLocalization = true;
calendarTemplate1.ColumnHeader.GetCell(0, 0).CellType = calendarHeaderCellType1;
calendarTemplate1.ColumnHeader.GetCell(0, 0).DateFormat = "{DayOfWeek}";
calendarTemplate1.ColumnHeader.GetCell(0, 0).CellStyle.Alignment = GrapeCity.Win.CalendarGrid.CalendarGridContentAlignment.MiddleCenter;
calendarTemplate1.Content.CellStyleName = "defaultStyle";
calendarTemplate1.Content.GetCell(0, 0).DateFormat = "d日";
calendarTemplate1.Content.GetCell(0, 0).DateFormatType = GrapeCity.Win.CalendarGrid.CalendarDateFormatType.DotNet;
return calendarTemplate1;
}
[STAThreadAttribute()]
public static void Main()
{
Application.EnableVisualStyles();
Application.Run(new VirtualModeDemo());
}
}
}
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Collections.Generic
Imports GrapeCity.Win.CalendarGrid
Namespace CalendarGridSampleCode
Class VirtualModeDemo
Inherits Form
Private gcCalendarGrid As New GcCalendarGrid()
Private _valueCache As New Dictionary(Of CalendarCellPosition, Object)()
Public Sub New()
gcCalendarGrid.Template = Me.CreateTemplate()
gcCalendarGrid.Dock = DockStyle.Fill
gcCalendarGrid.VirtualMode = True
AddHandler gcCalendarGrid.CellValueNeeded, AddressOf gcCalendarGrid_CellValueNeeded
AddHandler gcCalendarGrid.CellValuePushed, AddressOf gcCalendarGrid_CellValuePushed
Me.Text = "Virtual Mode Demo"
Me.Controls.Add(gcCalendarGrid)
End Sub
Private Sub gcCalendarGrid_CellValueNeeded(sender As Object, e As CalendarCellValueEventArgs)
If _valueCache.ContainsKey(e.CellPosition) Then
e.Value = _valueCache(e.CellPosition)
Else
e.Value = "Edit Me"
End If
End Sub
Private Sub gcCalendarGrid_CellValuePushed(sender As Object, e As CalendarCellValueEventArgs)
If _valueCache.ContainsKey(e.CellPosition) Then
'Same the value by your own.
_valueCache(e.CellPosition) = e.Value
Else
_valueCache.Add(e.CellPosition, e.Value)
'If the value is saved by user, change the back color.
Me.gcCalendarGrid(e.CellPosition.[Date])(e.CellPosition.RowIndex, e.CellPosition.ColumnIndex).CellStyle.BackColor = Color.Lime
End If
End Sub
Private Function CreateTemplate() As CalendarTemplate
Dim calendarTemplate1 As New CalendarTemplate()
Dim calendarHeaderCellType1 As New GrapeCity.Win.CalendarGrid.CalendarHeaderCellType()
calendarTemplate1.RowCount = 2
calendarTemplate1.RowHeaderColumnCount = 0
calendarTemplate1.ColumnHeader.CellStyleName = "defaultStyle"
calendarHeaderCellType1.SupportLocalization = True
calendarTemplate1.ColumnHeader.GetCell(0, 0).CellType = calendarHeaderCellType1
calendarTemplate1.ColumnHeader.GetCell(0, 0).DateFormat = "{DayOfWeek}"
calendarTemplate1.ColumnHeader.GetCell(0, 0).CellStyle.Alignment = GrapeCity.Win.CalendarGrid.CalendarGridContentAlignment.MiddleCenter
calendarTemplate1.Content.CellStyleName = "defaultStyle"
calendarTemplate1.Content.GetCell(0, 0).DateFormat = "d日"
calendarTemplate1.Content.GetCell(0, 0).DateFormatType = GrapeCity.Win.CalendarGrid.CalendarDateFormatType.DotNet
Return calendarTemplate1
End Function
<STAThreadAttribute> _
Public Shared Sub Main()
Application.EnableVisualStyles()
Application.Run(New VirtualModeDemo())
End Sub
End Class
End Namespace