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

Upvotes: 0

Views: 248

Answers (1)

Siva Rm K
Siva Rm K

Reputation: 294

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;
        }
    }

Upvotes: 1

Related Questions