到目前为止:我设法将一些有效的代码组合在一起,并使用标准高度为headercell的标准列显示标准datagridview。如果我在datagridview属性中设置columnheadercell height,则通常会接受高度。
目标:我希望在我自己的自定义datagridview中实现标准datagridviewtextboxcolumn的默认列标题高度,名为' datagridview_filter'。我想为新的datagridview永久设置自定义列标题高度。我很近但是......
这会创建我的自定义DGV:
Public Class DataGridView_Filter
End Class
使用基础.designer文件:
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
Partial Class DataGridView_Filter
Inherits System.Windows.Forms.DataGridView
'Control overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Control Designer
Private components As System.ComponentModel.IContainer
' NOTE: The following procedure is required by the Component Designer
' It can be modified using the Component Designer. Do not modify it
' using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
components = New System.ComponentModel.Container()
End Sub
End Class
我创建了一个新的自定义datagridviewcolumncell,名为&#39; datagridviewcolumncell_filter&#39;:
Public Class DataGridViewTextBoxColumn_Filter
Public Sub New()
Me.CellTemplate = New DataGridViewCell_Filter()
Me.ReadOnly = True
End Sub
End Class
使用基础.designer文件:
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
Partial Class DataGridViewTextBoxColumn_Filter
Inherits System.Windows.Forms.DataGridViewTextBoxColumn
'Control overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Control Designer
Private components As System.ComponentModel.IContainer
' NOTE: The following procedure is required by the Component Designer
' It can be modified using the Component Designer. Do not modify it
' using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
components = New System.ComponentModel.Container()
End Sub
结束班
和一个自定义datagridviewcell,名为&#39; datagridviewcell_filter&#39;:
Public Class DataGridViewCell_Filter Inherits DataGridViewTextBoxCell End Class
与底层.designer fie:
Partial Class DataGridViewCell_Filter
Inherits System.Windows.Forms.DataGridViewTextBoxCell
'Control overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()>
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Control Designer
Private components As System.ComponentModel.IContainer
' NOTE: The following procedure is required by the Component Designer
' It can be modified using the Component Designer. Do not modify it
' using the code editor.
<System.Diagnostics.DebuggerStepThrough()>
Private Sub InitializeComponent()
components = New System.ComponentModel.Container()
End Sub
End Class
修改 我偶然发现了“datagridview_filter [design]&#39;模式,我注意到我可以更改&#39; Datagridview_filter&#39;在[设计]模式下。想象我那幸福的脸那一刻。人们可以在那里设置任何东西。一切都得到保存,以备将来参考。但是......当我插入&#39; Datagridview_filter&#39;进入空白表单所有设置都会消失,好像它们永远不存在一样。所以我得到了columnheaderheight 18而不是40来保存在custom&quot; datagridview_filter [design]&#39;属性。所以我似乎和以前在同一个地方。
提前致谢
答案 0 :(得分:0)
我终于找到了解决方案。实际上很简单。这是标题设置为60的示例。
Public Class DataGridView_Filter
Inherits DataGridView
Private Sub DataGridView_Filter_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
Me.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
Me.ColumnHeadersHeight = 60
Me.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing
End Sub
End Class
因此,经过大量时间并获得'TUMBLEWEED'徽章后,我终于找到了这个解决方案。关于它的最好的事情......它是完全自定义的datagridview,可以直接从工具箱中使用。