Set font and color of certain rows at datagridview.

Posted on 2009-04-22
Last Modified: 2012-05-06

I want to set font  and color of certain rows of datagridview.

How could I do it?

Thank you.

Question by:emi_sastra
    LVL 48

    Expert Comment

    You can do somehting like this:

            Dim rowIndex As Byte = 1
            Me.DataGridView1.Rows(rowIndex).DefaultCellStyle.Font = New Font("Arial", 14, FontStyle.Bold)
            Me.DataGridView1.Rows(rowIndex).DefaultCellStyle.BackColor = Color.Beige

    Open in new window

    LVL 1

    Author Comment

    Hi jpaulino,

    At what event I should do the code?

    For example, I want to change it for Qty Order with certain amount ?

    Thank you.
    LVL 48

    Accepted Solution

    You can use CellValueChanged event
        Private Sub DataGridView1_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged
            Dim column As Byte = 2
            If e.RowIndex <> -1 AndAlso e.ColumnIndex <> -1 Then
                If Me.DataGridView1(1, e.RowIndex).Value > 50 Then
                    Me.DataGridView1.Rows(e.RowIndex).DefaultCellStyle.Font = New Font("Arial", 14, FontStyle.Bold)
                    Me.DataGridView1.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.Beige
                    Me.DataGridView1.Rows(e.RowIndex).DefaultCellStyle.Font = New Font("Arial", 10, FontStyle.Regular)
                    Me.DataGridView1.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.White
                End If
            End If
        End Sub

    Open in new window

    LVL 1

    Author Comment


    I try it later.

    Thank you very much for your help.


    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
    1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    745 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

    15 Experts available now in Live!

    Get 1:1 Help Now