问题
Using this code paint datagrid cell for special records when load data.
foreach (DataColumn item in dt.Columns)
{
FormattableTextBoxColumn tbcName = new FormattableTextBoxColumn();
if (item.ColumnName == "S")
{
tbcName.Width = 40;
tbcName.MappingName = item.ColumnName;
tbcName.HeaderText = item.ColumnName;
tbcName.SetCellFormat += new FormatCellEventHandler(ColumnSetCellFormat);
}
tableStyle.GridColumnStyles.Add(tbcName);
}
datagrid.TableStyles.Add(tableStyle);
Then highlight cell using below code:
SolidBrush highlightBrush = new SolidBrush(Color.Yellow);
private void ColumnSetCellFormat(object sender, DataGridFormatCellEventArgs e)
{
//Highlight color
if (datagrid[e.Row, 0].ToString() == "M")
{
e.BackBrush = highlightBrush;
}
}
Now problems is when i select one row, that row will highlight blue color. but if i select the row that had paint yellow, then the blue color is not showing, the yellow colour remain there, the difference is font color become white from black.
How to change the select row also become blue although base is yellow color?
来源:https://stackoverflow.com/questions/41673397/change-datagrid-selected-row-colour-after-paint