VB.NET - Hide the top left corner cell of a datagridview

788 views Asked by At

I have a datagridview with 3 rows and 2 columns. My rows and columns have headers.

The problem is that i have an empty cell on the top left corner of my datagridview. I think it is the column header of my rowheaders or something like that. I don't success to hide this cell, is it possible ?

Thank you

Example :

hide this cell  | colHead1| colHead2 |
--------------------------------------
firstname       | x       | y        |
lastname        | x1      | y1       |
society         | x2      | y2       |

EDIT : I tried to set the property dtgv.TopLeftHeaderCell.Visible to False, but it is ReadOnly.

1

There are 1 answers

0
OhBeWise On BEST ANSWER

I rescind my comment. You can accomplish this - manually. For example, in your DataGridView.CellPainting event handler in a bland/unmodified DataGridView, you can match the background like so:

If e.RowIndex < 0 AndAlso e.ColumnIndex < 0 Then
    Using brush As New SolidBrush(Me.dataGridView1.BackgroundColor)
        e.Graphics.FillRectangle(brush, e.CellBounds)
    End Using

    e.Handled = True
End If

enter image description here


i would like to show the background of the form

If you meant you want to set the DataGridView background to the Form's background these two (C#) answers by users Deumber and letsdance demonstrate the general setup to crop the correct portion of the Form's image into the DataGridView. Using their methods (without calling SetCellsTransparent()) coupled with the following change to your DataGridView.CellPainting event handler should work:

If e.RowIndex < 0 AndAlso e.ColumnIndex < 0 Then
    e.Graphics.FillRectangle(Brushes.Transparent, e.CellBounds)  
    e.Handled = True
End If

enter image description here