(C#) Format the cell of DataGridView based on the TextBox.Text

private void textBox1_TextChanged(object sender, EventArgs e)
        {
            DataGridViewCellStyle style = new DataGridViewCellStyle();
            style.Font = new Font(dataGridView1.Font.FontFamily, this.Font.Size, FontStyle.Bold);
            style.BackColor = Color.Yellow;//any style as you want;
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                foreach (DataGridViewCell cell in row.Cells)
                {
                    if (cell.Value != null && !string.IsNullOrEmpty(this.textBox1.Text) && cell.Value.ToString().Contains(this.textBox1.Text))
                    {
                        cell.Style = style;
                    }
                    else
                        cell.Style = dataGridView1.DefaultCellStyle;
                }
                
            }
        }

 Result:

原文地址:https://www.cnblogs.com/tony-MSDN/p/4372458.html