Establecer texto de dos colores en una sola celda DataGridView
Tengo una vista de cuadrícula de datos en mi aplicación de Windows C #. Necesito cambiar el color de los últimos 5 caracteres en una celda, pero no sé cómo hacerlo.
Tengo este código en el evento CellPainting pero no funciona:
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;
}
}
}
}
Este código muestra el DataGridView sin filas.