Dev Shed Forums - C Programming C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems. You can also talk about C# implementation in our .NET section below, when applicable. en Fri, 23 Mar 2018 11:37:15 GMT vBulletin 60 Dev Shed Forums - C Programming Find and colour text in DataGridView Thu, 22 Feb 2018 16:45:46 GMT This uses the DGV's CellFormatting event to search for text and apply a colour to it. Deleting the search text and performing the search again will remove the colour.

I'm using a TextBox and a Button to perform the search.
You could use a background colour instead, or both.
It searches every cell, but you could restrict it to particular columns using e.columnIndex.
This code was created using


public partial class Form1 : Form {
    string searchTerm = String.Empty;
    bool searching = false;

    public Form1() {

    private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) {
        if (searching && e.Value != null) {
            string stringValue = (string)e.Value;
            stringValue = stringValue.ToLower();
            if ((stringValue.IndexOf(searchTerm) > -1)) {
                e.CellStyle.ForeColor = Color.Red;

    private void button1_Click(object sender, EventArgs e) {
        searchTerm = textBox1.Text;
        searching = !String.IsNullOrWhiteSpace(searchTerm);

C Programming bnwebdesign1