using System;
using System.Windows.Forms;
using System.Drawing;
namespace GrapeCity.Win.MultiRow.SampleCode
{
class CellStyleDemo : Form
{
GcMultiRow gcMultiRow1 = new GcMultiRow();
public CellStyleDemo()
{
this.Text = "Cell Style Demo";
this.Size = new Size(500, 250);
InitializeGcMultiRow();
this.Controls.Add(gcMultiRow1);
this.Load += new EventHandler(Form1_Load);
}
void Form1_Load(object sender, EventArgs e)
{
// All cell's will use default cell style.
gcMultiRow1.RowsDefaultCellStyle.BackColor = Color.Black;
gcMultiRow1.RowsDefaultCellStyle.ForeColor = Color.White;
gcMultiRow1.RowsDefaultCellStyle.SelectionBackColor = Color.FromArgb(100, SystemColors.Highlight);
gcMultiRow1.RowsDefaultCellStyle.TextAlign = MultiRowContentAlignment.MiddleRight;
// The cell's in alternating Rows
gcMultiRow1.AlternatingRowsDefaultCellStyle.GradientColors = new Color[] { Color.FromArgb(25, 25, 25), Color.FromArgb(75, 75, 75) };
gcMultiRow1.AlternatingRowsDefaultCellStyle.GradientDirection = GradientDirection.Backward;
gcMultiRow1.AlternatingRowsDefaultCellStyle.GradientStyle = GradientStyle.Horizontal;
// Row header cells
gcMultiRow1.RowsDefaultHeaderCellStyle.BackColor = Color.FromArgb(75, 75, 75);
gcMultiRow1.RowsDefaultHeaderCellStyle.ForeColor = Color.White;
// column header cells.
gcMultiRow1.ColumnHeadersDefaultHeaderCellStyle.BackColor = Color.FromArgb(75, 75, 75);
gcMultiRow1.ColumnHeadersDefaultHeaderCellStyle.ForeColor = Color.FromArgb(200, 200, 200);
gcMultiRow1.ColumnHeadersDefaultHeaderCellStyle.TextAlign = MultiRowContentAlignment.MiddleCenter;
gcMultiRow1.ColumnHeadersDefaultHeaderCellStyle.UseCompatibleTextRendering = MultiRowTriState.True;
gcMultiRow1.ColumnHeadersDefaultHeaderCellStyle.TextEffect = TextEffect.SunkenLite;
// All cells is specific row.
gcMultiRow1.Rows[0].DefaultCellStyle.PatternColor = Color.Gray;
gcMultiRow1.Rows[0].DefaultCellStyle.PatternStyle = MultiRowHatchStyle.BackwardDiagonal;
gcMultiRow1.Rows[0].DefaultCellStyle.Font = new Font(Control.DefaultFont, FontStyle.Underline);
// Change single cell
gcMultiRow1[0, 0].Style.UseCompatibleTextRendering = MultiRowTriState.True;
gcMultiRow1[0, 0].Style.TextAngle = 30;
gcMultiRow1[0, 0].Style.Format = "#0.00%";
}
void gcMultiRow1_CellFormatting(object sender, CellFormattingEventArgs e)
{
// Customize cell style in cell formating.
if (e.Scope == CellScope.Row)
{
if (e.Value != null)
{
int value;
if (int.TryParse(e.Value.ToString(), out value))
{
// When cell's value more than 2 and less than 4, change fore color to red.
if (value >= 2 && value <= 4)
{
e.CellStyle.ForeColor = Color.Red;
}
}
}
}
}
private void InitializeGcMultiRow()
{
gcMultiRow1.Dock = DockStyle.Fill;
this.gcMultiRow1.ScrollBarOffice2007Style = Office2007Style.Black;
this.gcMultiRow1.SplitOffice2007Style = Office2007Style.Black;
gcMultiRow1.Template = CreateTemplate();
gcMultiRow1.RowCount = 30;
for (int rowIndex = 0; rowIndex < gcMultiRow1.RowCount; rowIndex++)
{
for (int cellIndex = 0; cellIndex < 10; cellIndex++)
{
this.gcMultiRow1.SetValue(rowIndex, cellIndex, rowIndex * 10 + cellIndex);
}
}
gcMultiRow1.ColumnHeaders[0][10].PerformHorizontalAutoFit();
gcMultiRow1.CellFormatting += new EventHandler<CellFormattingEventArgs>(gcMultiRow1_CellFormatting);
}
private static Template CreateTemplate()
{
Template template1 = Template.CreateGridTemplate(10);
for (int i = 0; i < 10; i++)
{
HeaderCell headerCell = template1.ColumnHeaders[0][i] as HeaderCell;
headerCell.Value = "Column" + i.ToString();
headerCell.FlatStyle = FlatStyle.Flat;
}
CornerHeaderCell cornerHeaderCell = template1.ColumnHeaders[0][10] as CornerHeaderCell;
cornerHeaderCell.FlatStyle = FlatStyle.Flat;
RowHeaderCell rowHeaderCell = template1.Row[10] as RowHeaderCell;
rowHeaderCell.FlatStyle = FlatStyle.Flat;
rowHeaderCell.ValueFormat = "1";
rowHeaderCell.Style.WordWrap = MultiRowTriState.False;
return template1;
}
[STAThreadAttribute()]
public static void Main()
{
Application.EnableVisualStyles();
Application.Run(new CellStyleDemo());
}
}
}
Imports System
Imports System.Windows.Forms
Imports System.Drawing
Imports GrapeCity.Win.MultiRow
Class CellStyleDemo
Inherits Form
Friend WithEvents gcMultiRow1 As New GcMultiRow()
Public Sub New()
Me.Text = "Cell Style Demo"
Me.Size = New Size(500, 250)
InitializeGcMultiRow()
Me.Controls.Add(gcMultiRow1)
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
' All cell's will use default cell style.
gcMultiRow1.RowsDefaultCellStyle.BackColor = Color.Black
gcMultiRow1.RowsDefaultCellStyle.ForeColor = Color.White
gcMultiRow1.RowsDefaultCellStyle.SelectionBackColor = Color.FromArgb(100, SystemColors.Highlight)
gcMultiRow1.RowsDefaultCellStyle.TextAlign = MultiRowContentAlignment.MiddleRight
' The cell's in alternating Rows
gcMultiRow1.AlternatingRowsDefaultCellStyle.GradientColors = New Color() {Color.FromArgb(25, 25, 25), Color.FromArgb(75, 75, 75)}
gcMultiRow1.AlternatingRowsDefaultCellStyle.GradientDirection = GradientDirection.Backward
gcMultiRow1.AlternatingRowsDefaultCellStyle.GradientStyle = GradientStyle.Horizontal
' Row header cells
gcMultiRow1.RowsDefaultHeaderCellStyle.BackColor = Color.FromArgb(75, 75, 75)
gcMultiRow1.RowsDefaultHeaderCellStyle.ForeColor = Color.White
' column header cells.
gcMultiRow1.ColumnHeadersDefaultHeaderCellStyle.BackColor = Color.FromArgb(75, 75, 75)
gcMultiRow1.ColumnHeadersDefaultHeaderCellStyle.ForeColor = Color.FromArgb(200, 200, 200)
gcMultiRow1.ColumnHeadersDefaultHeaderCellStyle.TextAlign = MultiRowContentAlignment.MiddleCenter
gcMultiRow1.ColumnHeadersDefaultHeaderCellStyle.UseCompatibleTextRendering = MultiRowTriState.True
gcMultiRow1.ColumnHeadersDefaultHeaderCellStyle.TextEffect = TextEffect.SunkenLite
' All cells is specific row.
gcMultiRow1.Rows(0).DefaultCellStyle.PatternColor = Color.Gray
gcMultiRow1.Rows(0).DefaultCellStyle.PatternStyle = MultiRowHatchStyle.BackwardDiagonal
gcMultiRow1.Rows(0).DefaultCellStyle.Font = New Font(Control.DefaultFont, FontStyle.Underline)
' Change single cell
gcMultiRow1(0, 0).Style.UseCompatibleTextRendering = MultiRowTriState.True
gcMultiRow1(0, 0).Style.TextAngle = 30
gcMultiRow1(0, 0).Style.Format = "#0.00%"
End Sub
Private Sub gcMultiRow1_CellFormatting(ByVal sender As Object, ByVal e As CellFormattingEventArgs) Handles gcMultiRow1.CellFormatting
' Customize cell style in cell formating.
If e.Scope = CellScope.Row Then
If e.Value <> Nothing Then
Dim value As Integer
If Integer.TryParse(e.Value.ToString(), value) Then
' When cell's value more than 2 and less than 4, change fore color to red.
If value >= 2 AndAlso value <= 4 Then
e.CellStyle.ForeColor = Color.Red
End If
End If
End If
End If
End Sub
Private Sub InitializeGcMultiRow()
gcMultiRow1.Dock = DockStyle.Fill
Me.gcMultiRow1.ScrollBarOffice2007Style = Office2007Style.Black
Me.gcMultiRow1.SplitOffice2007Style = Office2007Style.Black
gcMultiRow1.Template = CreateTemplate()
gcMultiRow1.RowCount = 30
For rowIndex As Integer = 0 To gcMultiRow1.RowCount - 1
For cellIndex As Integer = 0 To 9
Me.gcMultiRow1.SetValue(rowIndex, cellIndex, rowIndex * 10 + cellIndex)
Next
Next
gcMultiRow1.ColumnHeaders(0)(10).PerformHorizontalAutoFit()
End Sub
Private Shared Function CreateTemplate() As Template
Dim template1 As Template = Template.CreateGridTemplate(10)
For i As Integer = 0 To 9
Dim headerCell As HeaderCell = TryCast(template1.ColumnHeaders(0)(i), HeaderCell)
headerCell.Value = "Column" + i.ToString()
headerCell.FlatStyle = FlatStyle.Flat
Next
Dim cornerHeaderCell As CornerHeaderCell = TryCast(template1.ColumnHeaders(0)(10), CornerHeaderCell)
cornerHeaderCell.FlatStyle = FlatStyle.Flat
Dim rowHeaderCell As RowHeaderCell = TryCast(template1.Row(10), RowHeaderCell)
rowHeaderCell.FlatStyle = FlatStyle.Flat
rowHeaderCell.ValueFormat = "1"
rowHeaderCell.Style.WordWrap = MultiRowTriState.False
Return template1
End Function
<STAThreadAttribute()> _
Public Shared Sub Main()
Application.EnableVisualStyles()
Application.Run(New CellStyleDemo())
End Sub
End Class