I have a DataGridView and I want to put it into a GroupBox. In VB6 it looked like this:
So it is just a MsFlexGrid wrapped by a GroupBox. I've absolutely no idea, how to implement that in VB.NET.
I'd let it inherit from DataGridView, so it is a Control, and it has every Property of the DataGridView by default.
Public Class CaptionedDataGridView
Inherits DataGridView
There would also have to be a GroupBox:
Private xGroupBox as GroupBox
The text property would be overrided by the text of the group box as well as some size and placement properties (Top, Left, Width, Height)
Public Overrides Property Text As String
Get
Return xGroupBox.Text
End Get
Set(ByVal value As Integer)
xGroupBox.Text = value
End Set
End Property
Finally, if I'd create a new CaptionedDataGridView somewhere it should draw itself with the GroupBox sorrounded. How do I get from where I am right now to where I want to be?
I think you have to do that the other way around. Inherit from the GroupBox and add the DataGridView to it.
Simple example:
Public Class MyGrid
Inherits GroupBox
Private _Grid As DataGridView
Public Sub New()
_Grid = New DataGridView()
_Grid.Dock = DockStyle.Fill
Me.Controls.Add(_Grid)
End Sub
ReadOnly Property Grid As DataGridView
Get
Return _Grid
End Get
End Property
End Class
Of course, you don't have to do this as a custom control. You can just put a GroupBox on your form and add the DataGridView to it with that same DockStyle.Fill property.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.