• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 622
  • Last Modified:

Set font and color of certain rows at datagridview.

Hi,

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

How could I do it?

Thank you.

0
emi_sastra
Asked:
emi_sastra
  • 2
  • 2
1 Solution
 
jpaulinoCommented:
Hi,
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

0
 
emi_sastraAuthor Commented:
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.
0
 
jpaulinoCommented:
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
            Else
                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

0
 
emi_sastraAuthor Commented:
Ok.

I try it later.

Thank you very much for your help.

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now