Data grid table header Grid color

This is a VB.NET application in which we show the output of an SQL statement in a Datagrid view. using .NET 2005.

We need the header separators on the grid control to be the same color as the GridColor in the form. See the picture below:

alt text

We tried to look at all the properties of the DataGridView control and found interesting things that looked promising, such as DataGridViewAdvancedHeaderStyle and DataGridViewHeaderBorderStyle, but none of this allows you to change colors on it.

Does anyone know how to do this without redoing the whole thing with the GDI + control?

+1
source share
2 answers

Well, I never found a property for this, so I created a custom component and overloaded the OnPaint event handler to draw a line on top of the existing one.

Here is the code for it if anyone else 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 
+2
source

I don’t see the image, but what about playing with them?

 DataGridView.ColumnBordersHeaderStyle DataGridView.RowBordersHeaderStyle 
0
source

All Articles