Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

Change Cell Color

$
0
0

Hi,

My code below will loop through my DGV rows and if the requested string is found the cell color should change.

However, sometimes the code needs to be called multiple times for cell change to take effect.

Any ideas?

Thanks!

foreach (DataGridViewColumn col in myDataGridView.Columns)
            {
                foreach (DataGridViewRow row in myDataGridView.Rows)
                {
                    if (row.Cells[col.Name].Value != null)
                    {
                        if (row.Cells[col.Name].Value.ToString().IndexOf(TextToFind, StringComparison.InvariantCultureIgnoreCase) != -1)
                        {
                            // highlight cell
                            row.Cells[col.Name].Style.BackColor = Color.LightYellow;
                        }
                    }
                }
            }


Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>