Change datagrid selected row colour after paint

依然范特西╮ 提交于 2019-12-24 10:48:50

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!