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

假如想象 提交于 2019-12-11 06:10:04

问题


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:


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


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



来源:https://stackoverflow.com/questions/41243456/vb-net-hide-the-top-left-corner-cell-of-a-datagridview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!