複数のCellStyleの効果を組み合わせて新しいCellStyleを生成できる特別な
CellStyleを表します。このクラスは継承できません。
次のサンプルコードは、定義済みの2つの
CellStyleを組み合わせて必要なCellStyleを生成する方法を示します。このプログラムでは、交互列に
RoundedBorderを設定します。このサンプルコードは、
NamedCellStyleクラスに示されている詳細なコード例の一部を抜粋したものです。
void SetBorderToAlternatingColumns(object sender, EventArgs e)
{
CellStyle borderCellStyle = new CellStyle();
borderCellStyle.Border = new RoundedBorder(LineStyle.Thin, Color.Gray, 0.5f);
CellStyle colorStyle = new CellStyle();
colorStyle.BackColor = Color.Yellow;
//The combinedCellStyle1 will merge borderCellStyle and AlternatingColumnsDefaultCellStyle.
CombinedCellStyle combinedCellStyle1 = new CombinedCellStyle();
combinedCellStyle1.Items.AddRange(new CellStyle[] { borderCellStyle, colorStyle });
this.gcMultiRow1.NamedCellStyles["AlternatingColumnsDefaultCellStyle"] = combinedCellStyle1;
}
Private Sub SetBorderToAlternatingColumns(ByVal sender As Object, ByVal e As EventArgs) Handles setBorder.Click
Dim borderCellStyle As New CellStyle()
borderCellStyle.Border = New RoundedBorder(LineStyle.Thin, Color.Gray, 0.5F)
Dim colorStyle As New CellStyle()
colorStyle.BackColor = Color.Yellow
'The combinedCellStyle1 will merge borderCellStyle and AlternatingColumnsDefaultCellStyle.
Dim combinedCellStyle1 As New CombinedCellStyle()
combinedCellStyle1.Items.AddRange(New CellStyle() {borderCellStyle, colorStyle})
Me.gcMultiRow1.NamedCellStyles("AlternatingColumnsDefaultCellStyle") = combinedCellStyle1
End Sub