Вопрос

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

Это было полезно?

Решение

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.

Другие советы

Use split panel, then insert your toolbar into panel 1 and datagridview into panel 2.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top