The problem here is that your Toolstrip
is a control inside your DataGridView
, and as such its location origin (0,0) is the top left corner of the DataGridView
.
In this instance you might be better off creating a User Control that allows you to place your Toolstrip
above your DataGridView
. You would expose both of them as properties so that you can still access the controls' own properties and methods, and add a property to turn display of the Toolstrip
on or off, and set the position of the DataGridView
appropriately:
Dim _ShowToolbar As Boolean
Dim _Toolbox As Toolstrip
Public Property ShowToolbar() As Boolean
Get
Return _ShowToolbar
End Get
Set(ByVal value As Boolean)
_ShowToolbar = value
If value Then
If _Toolbox Is Nothing Then
_Toolbox = New Toolstrip()
Me.Controls.Add(_Toolbox)
End If
_Toolbox.Location = New System.Drawing.Point(0,0)
_DataGridView.Location = New System.Drawing.Point(0,_Toolbox.Size.Height)
_Toolbox.Visible = True
Else
_Toolbox.Visible = False
_DataGridView.Location = New System.Drawing.Point(0,0)
End If
End Set
End Property
All of that is from brain compiler, so there might be errors in there, but it should get you started.