private void DataGridView_RowPostPaint(object sender,
DataGridViewRowPostPaintEventArgs e)
{
DataGridView dgv = (DataGridView)sender;
// 行に色をつける
if (e.RowIndex % 2 == 0)
{
// 偶数行
dgv.Rows[e.RowIndex].DefaultCellStyle.BackColor =
CommonInfo.DataGridViewEvenRowBackColor;
}
else
{
// 奇数行
dgv.Rows[e.RowIndex].DefaultCellStyle.BackColor =
CommonInfo.DataGridViewOddRowBackColor;
}
// 選択行の前景色セット
dgv.Rows[e.RowIndex].DefaultCellStyle.SelectionForeColor =
CommonInfo.DataGridViewSelectionRowForeColor;
// 選択行の背景色セット
dgv.Rows[e.RowIndex].DefaultCellStyle.SelectionBackColor = CommonInfo.DataGridViewSelectionRowBackColor;
}
本文介绍如何在DataGridView控件中为偶数行和奇数行设置不同的背景颜色,并调整选中行的颜色。
4613

被折叠的 条评论
为什么被折叠?



