VS 2015 [RESOLVED] How to change the font color of a DatagridView specific Column?-VBForums
Results 1 to 5 of 5

Thread: [RESOLVED] How to change the font color of a DatagridView specific Column?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2014
    Posts
    263

    Resolved [RESOLVED] How to change the font color of a DatagridView specific Column?

    How to change the font color of a DatagridView specific Column? I have five Datagridview columns in which the 5th column has Totals. How to change the font color of column 5th to Color.Red?

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    21,563

    Re: How to change the font color of a DatagridView specific Column?

    try this...

    Code:
    DataGridView1.Columns(index).DefaultCellStyle.ForeColor = Color.Red

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2014
    Posts
    263

    Re: How to change the font color of a DatagridView specific Column?

    Thanks. It is fine. It resolved my problem. But can we also change the color of the selected cell?
    Attached Images Attached Images  

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    21,563

    Re: How to change the font color of a DatagridView specific Column?

    if you're talking about the forecolor...

    Code:
    Private Sub DataGridView1_CellEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEnter
        If e.ColumnIndex = 4 Then
            DataGridView1(e.ColumnIndex, e.RowIndex).Style.ForeColor = Color.Magenta
        End If
    End Sub
    
    Private Sub DataGridView1_CellLeave(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellLeave
        If e.ColumnIndex = 4 Then
            DataGridView1(e.ColumnIndex, e.RowIndex).Style.ForeColor = Color.Red
        End If
    End Sub

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2014
    Posts
    263

    Re: How to change the font color of a DatagridView specific Column?

    Code:
    Me.dgvSales.Columns(28).DefaultCellStyle.ForeColor = Color.Red
    The above code makes the fore color Red. But the below code doesn't make any color changes and no error as well.

    Code:
    Private Sub dgvSales_CellEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvSales.CellEnter
            If e.ColumnIndex = 28 Then
                dgvSales(e.ColumnIndex, e.RowIndex).Style.ForeColor = Color.Blue
            End If
        End Sub
        Private Sub dgvSales_CellLeave(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvSales.CellLeave
            If e.ColumnIndex = 28 Then
                dgvSales(e.ColumnIndex, e.RowIndex).Style.ForeColor = Color.Red
            End If
        End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width