作成日: 2014/09/26 最終更新日: 2014/09/26
文書種別
使用方法
詳細
行や列、セル単位で外観を変更することができます。
カレントセルや選択されているセルといったようなステータスに基づいて変更する方法や正規表現を使用してセルの値に応じて外観を変更することも可能です。こちらの内容については、製品ヘルプの下記項目を参照してください。
[True DBGrid for .NETユーザーガイド]
- [True DBGrid for .NET の使い方]
- [スタイルの使用方法]
- [セルにスタイルを適用する]
行単位で変更する

フォントや背景色等を行単位で変更するには、FetchRowStyleイベントを使用します。FetchRowStyleイベントは、グリッドのFetchRowStylesプロパティがTrueに設定されている場合のみ発生することに注意してください。 1行おきに行の背景色などを変更する場合は、AlternatingRowsプロパティをTrueに設定し、組み込みスタイルのEvenRowStyleプロパティおよびOddRowStyleプロパティを使用すると、より効率よく表示できます。
[True DBGrid for .NETユーザーガイド]
- [グリッドの外見をカスタマイズする]
- [行の色を互い違いにする]
- [チュートリアル]
- [チュートリアル12 - 行の色を互い違いに表示する]
◎サンプルコード(VB)
◎サンプルコード(C#)
private void Form1_Load(object sender, EventArgs e)
{
...
// FetchRowStyleイベントを発生させます
c1TrueDBGrid1.FetchRowStyles = true;
}
private void c1TrueDBGrid1_FetchRowStyle(object sender, C1.Win.C1TrueDBGrid.FetchRowStyleEventArgs e)
{
// 3行目の背景色を変更
if (e.Row == 3)
{
e.CellStyle.BackColor = System.Drawing.Color.Yellow;
}
// 5行目のフォント/前景色を変更
if (e.Row == 5)
{
e.CellStyle.Font = new Font("MS ゴシック", 10, FontStyle.Bold);
e.CellStyle.ForeColor = Color.Red;
}
}
列単位で変更する

フォントや背景色、前景色等を列単位で変更する場合は、DisplayColumnsオブジェクトのStyleプロパティを使用します。
◎サンプルコード(VB)
◎サンプルコード(C#)
セル単位で変更する

フォントや背景色、前景色等をセル単位で変更する場合は、FetchCellStyleイベントを使用します。FetchCellStyleイベントは、変更したいセルがある列のFetchStyleプロパティをTrueに設定することで発生します。
◎サンプルコード(VB)
◎サンプルコード(C#)
private void Form1_Load(object sender, EventArgs e)
{
...
// 2列目でFetchCellStyleイベントを発生させます
c1TrueDBGrid1.Splits[0].DisplayColumns[2].FetchStyle = true;
}
private void c1TrueDBGrid1_FetchCellStyle(object sender, C1.Win.C1TrueDBGrid.FetchCellStyleEventArgs e)
{
// 2行2列目のセルの背景色を変更
if ((e.Col == 2) && (e.Row == 2))
{
e.CellStyle.BackColor = Color.Yellow;
}
// 4行2列目のセルのフォントを変更
if ((e.Col == 2) && (e.Row == 4))
{
e.CellStyle.Font = new Font("MS ゴシック", 10, FontStyle.Bold);
}
}
カレントセルや選択されているセルといったようなステータスに基づいて変更する方法や正規表現を使用してセルの値に応じて外観を変更することも可能です。こちらの内容については、製品ヘルプの下記項目を参照してください。
[True DBGrid for .NETユーザーガイド]
- [True DBGrid for .NET の使い方]
- [スタイルの使用方法]
- [セルにスタイルを適用する]
行単位で変更する

フォントや背景色等を行単位で変更するには、FetchRowStyleイベントを使用します。FetchRowStyleイベントは、グリッドのFetchRowStylesプロパティがTrueに設定されている場合のみ発生することに注意してください。 1行おきに行の背景色などを変更する場合は、AlternatingRowsプロパティをTrueに設定し、組み込みスタイルのEvenRowStyleプロパティおよびOddRowStyleプロパティを使用すると、より効率よく表示できます。
[True DBGrid for .NETユーザーガイド]
- [グリッドの外見をカスタマイズする]
- [行の色を互い違いにする]
- [チュートリアル]
- [チュートリアル12 - 行の色を互い違いに表示する]
◎サンプルコード(VB)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
...
' FetchRowStyleイベントを発生させます
C1TrueDBGrid1.FetchRowStyles = True
End Sub
Private Sub C1TrueDBGrid1_FetchRowStyle(ByVal sender As Object, ByVal e As C1.Win.C1TrueDBGrid.FetchRowStyleEventArgs) Handles C1TrueDBGrid1.FetchRowStyle
' 3行目の背景色を変更
If e.Row = 3 Then
e.CellStyle.BackColor = Color.Yellow
End If
' 5行目のフォント/前景色を変更
If e.Row = 5 Then
e.CellStyle.Font = New Font("MS ゴシック", 10, FontStyle.Bold)
e.CellStyle.ForeColor = Color.Red
End If
End Sub
...
' FetchRowStyleイベントを発生させます
C1TrueDBGrid1.FetchRowStyles = True
End Sub
Private Sub C1TrueDBGrid1_FetchRowStyle(ByVal sender As Object, ByVal e As C1.Win.C1TrueDBGrid.FetchRowStyleEventArgs) Handles C1TrueDBGrid1.FetchRowStyle
' 3行目の背景色を変更
If e.Row = 3 Then
e.CellStyle.BackColor = Color.Yellow
End If
' 5行目のフォント/前景色を変更
If e.Row = 5 Then
e.CellStyle.Font = New Font("MS ゴシック", 10, FontStyle.Bold)
e.CellStyle.ForeColor = Color.Red
End If
End Sub
◎サンプルコード(C#)
private void Form1_Load(object sender, EventArgs e)
{
...
// FetchRowStyleイベントを発生させます
c1TrueDBGrid1.FetchRowStyles = true;
}
private void c1TrueDBGrid1_FetchRowStyle(object sender, C1.Win.C1TrueDBGrid.FetchRowStyleEventArgs e)
{
// 3行目の背景色を変更
if (e.Row == 3)
{
e.CellStyle.BackColor = System.Drawing.Color.Yellow;
}
// 5行目のフォント/前景色を変更
if (e.Row == 5)
{
e.CellStyle.Font = new Font("MS ゴシック", 10, FontStyle.Bold);
e.CellStyle.ForeColor = Color.Red;
}
}
列単位で変更する

フォントや背景色、前景色等を列単位で変更する場合は、DisplayColumnsオブジェクトのStyleプロパティを使用します。
◎サンプルコード(VB)
' 0列目の背景色を変更
C1TrueDBGrid1.Splits(0).DisplayColumns(0).Style.BackColor = Color.YellowGreen
C1TrueDBGrid1.Splits(0).DisplayColumns(0).Style.BackColor = Color.YellowGreen
◎サンプルコード(C#)
// 0列目の背景色を変更
c1TrueDBGrid1.Splits[0].DisplayColumns[0].Style.BackColor = Color.YellowGreen;
c1TrueDBGrid1.Splits[0].DisplayColumns[0].Style.BackColor = Color.YellowGreen;
セル単位で変更する

フォントや背景色、前景色等をセル単位で変更する場合は、FetchCellStyleイベントを使用します。FetchCellStyleイベントは、変更したいセルがある列のFetchStyleプロパティをTrueに設定することで発生します。
◎サンプルコード(VB)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
...
' 2列目でFetchCellStyleイベントを発生させます
C1TrueDBGrid1.Splits(0).DisplayColumns(2).FetchStyle = True
End Sub
Private Sub C1TrueDBGrid1_FetchCellStyle(ByVal sender As Object, ByVal e As C1.Win.C1TrueDBGrid.FetchCellStyleEventArgs) Handles C1TrueDBGrid1.FetchCellStyle
' 2行2列目のセルの背景色を変更
If (e.Col = 2) And (e.Row = 2) Then
e.CellStyle.BackColor = Color.Yellow
End If
' 4行2列目のセルのフォント/前景色を変更
If (e.Col = 2) And (e.Row = 4) Then
e.CellStyle.Font = New Font("MS ゴシック", 10, FontStyle.Bold)
e.CellStyle.ForeColor = Color.Red
End If
End Sub
...
' 2列目でFetchCellStyleイベントを発生させます
C1TrueDBGrid1.Splits(0).DisplayColumns(2).FetchStyle = True
End Sub
Private Sub C1TrueDBGrid1_FetchCellStyle(ByVal sender As Object, ByVal e As C1.Win.C1TrueDBGrid.FetchCellStyleEventArgs) Handles C1TrueDBGrid1.FetchCellStyle
' 2行2列目のセルの背景色を変更
If (e.Col = 2) And (e.Row = 2) Then
e.CellStyle.BackColor = Color.Yellow
End If
' 4行2列目のセルのフォント/前景色を変更
If (e.Col = 2) And (e.Row = 4) Then
e.CellStyle.Font = New Font("MS ゴシック", 10, FontStyle.Bold)
e.CellStyle.ForeColor = Color.Red
End If
End Sub
◎サンプルコード(C#)
private void Form1_Load(object sender, EventArgs e)
{
...
// 2列目でFetchCellStyleイベントを発生させます
c1TrueDBGrid1.Splits[0].DisplayColumns[2].FetchStyle = true;
}
private void c1TrueDBGrid1_FetchCellStyle(object sender, C1.Win.C1TrueDBGrid.FetchCellStyleEventArgs e)
{
// 2行2列目のセルの背景色を変更
if ((e.Col == 2) && (e.Row == 2))
{
e.CellStyle.BackColor = Color.Yellow;
}
// 4行2列目のセルのフォントを変更
if ((e.Col == 2) && (e.Row == 4))
{
e.CellStyle.Font = new Font("MS ゴシック", 10, FontStyle.Bold);
}
}
旧文書番号
69960