作成日: 2013/06/25 最終更新日: 2024/07/10
文書種別
使用方法
詳細
◆.NET Framework
セル単位でセルの背景色や前景色を変更するには、CellFactoryを継承するクラスを作成してApplyCellStylesメソッドをオーバーライドし、Borderの背景色と、Borderの子のTextBlockの前景色を設定します。
◎サンプルコード(VB)
Imports C1.WPF.FlexGrid
Public Sub New()
:
C1FlexGrid1.CellFactory = New MyCellFactory
End Sub
Public Class MyCellFactory
Inherits CellFactory
Public Overrides Sub ApplyCellStyles(grid As C1FlexGrid, cellType As CellType, rng As CellRange, bdr As Border)
MyBase.ApplyCellStyles(grid, cellType, rng, bdr)
If cellType = C1.WPF.FlexGrid.CellType.Cell Then
If rng.Column = 1 AndAlso rng.Row = 1 Then
' セルの背景色と前景色を変更します
bdr.Background = New SolidColorBrush(Colors.Red)
Dim tb As TextBlock = bdr.Child
If tb IsNot Nothing Then
tb.Foreground = New SolidColorBrush(Colors.White)
End If
End If
End If
End Sub
End Class
◎サンプルコード(C#)
using C1.WPF.FlexGrid;
public MainPage()
{
:
c1FlexGrid1.CellFactory = new MyCellFactory();
}
public class MyCellFactory : CellFactory
{
public override void ApplyCellStyles(C1FlexGrid grid, CellType cellType, CellRange rng, Border bdr)
{
base.ApplyCellStyles(grid, cellType, rng, bdr);
if (cellType == CellType.Cell)
{
if (rng.Column == 1 && rng.Row == 1)
{
// セルの背景色と前景色を変更します
bdr.Background = new SolidColorBrush(Colors.Red);
var tb = bdr.Child as TextBlock;
if (tb != null)
{
tb.Foreground = new SolidColorBrush(Colors.White);
}
}
}
}
}
◆.NET
GridCellFactoryを継承するクラスを作成してPrepareCellメソッドをオーバーライドし、セルの背景色と前景色を設定します。
GridCellFactoryを継承するクラスを作成してPrepareCellメソッドをオーバーライドし、セルの背景色と前景色を設定します。
◎サンプルコード(C#)
public MainWindow()
{
InitializeComponent();
flexgrid.CellFactory = new MyCellFactory();
}
public class MyCellFactory : C1.WPF.Grid.GridCellFactory
{
public override void PrepareCell(C1.WPF.Grid.GridCellType cellType, C1.WPF.Grid.GridCellRange range, C1.WPF.Grid.GridCellView cell, Thickness internalBorders)
{
base.PrepareCell(cellType, range, cell, internalBorders);
if (cellType == C1.WPF.Grid.GridCellType.Cell)
{
if (range.Column == 0 && range.Row == 0)
{
// セルの前景色を変更します
cell.Foreground = Brushes.Blue;
}
if (range.Column == 1 && range.Row == 1)
{
// セルの背景色を変更します
cell.Background = Brushes.Red;
}
}
}
}
旧文書番号
80194