views:

306

answers:

2

This is a VB .NET application where we are showing the output of a SQL statement in a Datagrid view. using .NET 2005.

We need to get the seperators of the headers on the grid control to be the same colors as the GridColor on the form. See the picture below:

alt text

We've tried looking through all of the properties of the DataGridView control, and found some interesting things that looked promising such as the DataGridViewAdvancedHeaderStyle, and DataGridViewHeaderBorderStyle, but none of it seems to allow you to change the colors on it.

Does anyone know how to do this without remaking the entire thing with a GDI+ control?

A: 

I can't see the picture but what about playing with these?

DataGridView.ColumnBordersHeaderStyle
DataGridView.RowBordersHeaderStyle
John at CashCommons
The ColumnBorderHeaderStyle does not exist in framework 2.0 The closest thing we could find to this is the ColumnHeadersBorderStyle which is just an enumeration of how it looks, no color specification.The RowBorderHeaderStyle contains properties for Row headers and we are having problems with Column headers... I don't believe that the settings transfer from one to another.
Jrud
A: 

Well, I never did find a property for this, so I ended up creating a custom component, and overloading the OnPaint event handler to draw a line over the existing one.

Here is the code for it if anyone else ever comes across this post looking for a solution:

Private Sub CustomDataGridView_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    Dim g As Graphics = e.Graphics
    Dim pen As New Pen(Me.GridColor)
    Dim TWidth As Integer = 2
    Dim HeaderWidth As Integer = 0
    If Me.RowHeadersVisible Then
        HeaderWidth = Me.RowHeadersWidth
    End If
    For Each column As DataGridViewColumn In Me.Columns
        Dim x As Integer = HeaderWidth + TWidth - 1
        TWidth += column.Width
        Dim top As Integer = column.HeaderCell.ContentBounds.Top
        Dim bottom As Integer = column.HeaderCell.ContentBounds.Bottom + 1
        pen.Width = 2
        g.DrawLine(pen, x, top, x, bottom)
    Next column
End Sub
Jrud