VB.NET - 隐藏datagridview的左上角单元格 [英] VB.NET - Hide the top left corner cell of a datagridview
问题描述
我有一个3行2列的datagridview。我的行和列都有标题。
问题是我在datagridview的左上角有一个空单元格。我认为这是我的rowheaders的列标题或类似的东西。我没有成功隐藏这个细胞,这有可能吗?
谢谢
示例:
隐藏此单元| colHead1 | colHead2 |
--------------------------------------
firstname | x | y |
姓氏| x1 | y1 |
society | x2 | y2 |
编辑:
我试着设置属性 dtgv.TopLeftHeaderCell.Visible
为False,但它是ReadOnly。
取消我的评论。您可以 完成此操作 - 手动。例如,在一个平淡/未修改的 DataGridView
中的 DataGridView.CellPainting
事件处理程序中,您可以像这样匹配背景:
如果e.RowIndex< 0还有e.ColumnIndex< 0然后
使用笔刷作为新的SolidBrush(Me.dataGridView1.BackgroundColor)
e.Graphics.FillRectangle(brush,e.CellBounds)
结束使用
e。 Handled = True
End If
我想要显示表格的背景
如果你的意思是你想要设置 DataGridView
背景到Form的背景,这两个(C#)答案用户
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.
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
这篇关于VB.NET - 隐藏datagridview的左上角单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!