简体   繁体   中英

Change textcolor of a row in a datagridview if a cell contains part of text c#

How is it possible to change a whole row forecolor, if a cell in that row contains some text?

I have a code like this but it only changes the color of the cell that contains the exact word.

private void constringview_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
    {
        if (e.Value != null && e.Value.ToString() == "838")
        {
            e.CellStyle.ForeColor = Color.BlueViolet;
        }

    }

I would like to color the whole row, if a cell contains a part of a word

You can access the row, by getting Row index form DataGridViewCellFormattingEventArgs as below

private void constringview_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
    {
        if (e.Value != null && e.Value.ToString() == "838")
        {    
           dataGridView1.Rows[e.RowIndex].DefaultCellStyle.ForeColor = Color.BlueViolet;
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM