0
我在C#Windows应用程序中有一个数据网格视图。 我需要改变单元格中最后5个字符的颜色,但我不知道如何去做。在单个DataGridView中设置两种颜色文本单元格
我在CellPainting事件这个代码,但不工作:
private void dgvSorteados_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
int sector = 0;
int.TryParse(dgvSorteados.Rows[e.RowIndex].Cells[0].Value.ToString(), out sector);
if (sector == 3 && rdbSenete3.Checked)
{
if (dgvSorteados.Columns[1].Index == e.ColumnIndex && e.RowIndex >= 0)
{
string bolillas = (String)e.Value;
string[] bolillasArray = bolillas.Split('-');
string bolillasMin = string.Join("-", bolillasArray.Take(12));
string bolillasResto = string.Join("-", bolillasArray.Skip(12));
using (Brush gridBrush = new SolidBrush(dgvSorteados.GridColor), backColorBrush = new SolidBrush(e.CellStyle.BackColor))
{
// Erase the cell.
e.Graphics.FillRectangle(backColorBrush, e.CellBounds);
// Draw the text content of the cell, ignoring alignment.
e.Graphics.DrawString((String)bolillasMin, e.CellStyle.Font, Brushes.Black, e.CellBounds.X + 2, e.CellBounds.Y + 2, StringFormat.GenericDefault);
if (!string.IsNullOrEmpty(bolillasResto))
{
e.Graphics.DrawString("-" + (String)bolillasResto, e.CellStyle.Font, Brushes.Crimson, e.CellBounds.X + 2 + bolillasMin.Length, e.CellBounds.Y + 2, StringFormat.GenericDefault);
}
e.Handled = true;
}
}
}
}
这段代码显示无行的DataGridView。
这就是我想要的,但现在的问题是,在DataGridView显示所有深灰色,如果我上出现一排点击。 –
@Phoenix_uy检查您是否设置了与网格背景颜色相同的前景色 – Junaith
我在哪里检查? –