Imports GrapeCity.Win.CalendarGrid
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
InitStyle()
End Sub
Private Sub InitStyle()
' ユーザー定義のセルスタイルを設定します。
Dim cellStyle As New CalendarDynamicCellStyle()
cellStyle.Condition = New DynamicCellStyleCondition(AddressOf GetDayStyle)
cellStyle.Name = "style"
GcCalendarGrid1.Styles.Add(cellStyle)
' 2行1列目のセルにユーザー定義のセルスタイルを設定します。
GcCalendarGrid1.Template.Content.GetCell(1, 0).CellStyleName = "style"
End Sub
Public Function GetDayStyle(context As CellStyleContext) As CalendarCellStyle
Dim cellStyle As New CalendarCellStyle()
Dim cell As CalendarCell = GcCalendarGrid1(context.CellPosition.Date)(context.CellPosition.RowIndex, context.CellPosition.ColumnIndex)
If cell.Value IsNot Nothing Then
' 条件にあわせてセルの背景色を設定します。
If (Integer.Parse(cell.Value.ToString()) > 10) Then
cellStyle.BackColor = Color.Yellow
ElseIf (Integer.Parse(cell.Value.ToString()) < 0) Then
cellStyle.BackColor = Color.Red
End If
End If
Return cellStyle
End Function
using GrapeCity.Win.CalendarGrid;
private void Form1_Load(object sender, EventArgs e)
{
InitStyle();
}
private void InitStyle()
{
// ユーザー定義のセルスタイルを設定します。
CalendarDynamicCellStyle cellStyle = new CalendarDynamicCellStyle();
cellStyle.Condition = new DynamicCellStyleCondition(GetDayStyle);
cellStyle.Name = "style";
gcCalendarGrid1.Styles.Add(cellStyle);
// 2行1列目のセルにユーザー定義のセルスタイルを設定します。
gcCalendarGrid1.Template.Content.GetCell(1, 0).CellStyleName = "style";
}
public CalendarCellStyle GetDayStyle(CellStyleContext context)
{
CalendarCellStyle cellStyle = new CalendarCellStyle();
CalendarCell cell = gcCalendarGrid1[context.CellPosition.Date][context.CellPosition.RowIndex, context.CellPosition.ColumnIndex];
if (cell.Value != null)
{
// 条件にあわせてセルの背景色を設定します。
if (int.Parse(cell.Value.ToString()) > 10)
{
cellStyle.BackColor = Color.Yellow;
}
else if (int.Parse(cell.Value.ToString()) < 0)
{
cellStyle.BackColor = Color.Red;
}
}
return cellStyle;
}