Conditional Formating In DataGridView

Posted on 2007-10-02
Last Modified: 2010-04-23
I have a datagridview that I would like the entire row to be a background of green if the column called Status = "Complete" for that particular row/record.  Thanks in advance..
Question by:H-SC
    LVL 48

    Expert Comment

    You can use this code in the datagridview cellendedit event

    If myDataGridView("Status", e.RowIndex).Value = "Complete" Then
      myDataGridView.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.Green
      myDataGridView.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.White
    End If

    LVL 1

    Author Comment


    I am using tis form for display only and not allowing edits.  I have a timer attached to it to refresh.  I tried puting the code on the timer event but it does not like thr "e", any ideas??
    LVL 48

    Accepted Solution

    No problem! You can add this to your timer

    For Each row As DataGridViewRow In myDataGridView.Rows
    If myDataGridView("Status", row.Index).Value = "Complete" Then
      myDataGridView.Rows(row.Index).DefaultCellStyle.BackColor = Color.Green
      myDataGridView.Rows(row.Index).DefaultCellStyle.BackColor = Color.White
    End If
    LVL 1

    Author Comment


    Works great!!  Many thanks

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now