0

I created a custom control that inherits a datagridview and add some custom properties. I just add a toolbar control docked on top of it so it can have functionalities like add row, delete row etc. but it displays like this image below:

enter image description here

as you can see the columnheader was under the toolbox control...I just want them not to overlap each other...please help.

EDIT

I just insert a custom property like this one:

Dim _Toolbox_ As Toolstrip
Dim _ShowToolbar As Boolean

Public Property ShowToolbar() As Boolean
    Get
        Return _ShowToolbar
    End Get
    Set(ByVal value As Boolean)
        _ShowToolbar = value
        If value = True Then
            _Toolbox_ = New Toolstrip
            MyBase.Controls.Add(_Toolbox_)
            _Toolbox_.Dock = Windows.Forms.DockStyle.Top
            _Toolbox_.Visible = True
        Else
            MyBase.Controls.Remove(_Toolbox_)
            _Toolbox_ = Nothing
        End If
    End Set

End Property

4

2 回答 2

1

这里的问题是您Toolstrip是您的内部的一个控件DataGridView,因此它的位置原点 (0,0) 是DataGridView.

在这种情况下,您最好创建一个用户控件,允许您将您ToolstripDataGridView. 您将它们都公开为属性,以便您仍然可以访问控件自己的属性和方法,并添加一个属性来打开Toolstrip或关闭显示,并适当地设置位置DataGridView

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

所有这些都来自大脑编译器,因此其中可能存在错误,但它应该可以帮助您入门。

于 2013-08-20T03:22:31.613 回答
0

使用拆分面板,然后将工具栏插入面板 1,将 datagridview 插入面板 2。

于 2013-09-05T14:20:16.147 回答