自定义DataGridViewRowCollection的问题

时间:2018-12-17 15:46:00

标签: vb.net thread-safety custom-controls vb.net-2010

我目前正在从事多线程项目。这个想法是将威胁安全性实现到我自己的自定义控件中。现在,我想使用威胁安全代码来覆盖DataGridViewRowCollection的属性,例如DataGridView.Rows.Add()DataGridView.Rows.Remove(row as DataGridViewRow)

我的想法是使用自己的DataGridViewRowCollection XRowCollection而不是基本的DataGridViewRowCollection。当我尝试覆盖Rows属性时,收到编译器消息:

  

“公共重写为XRowCollection的只读属性行”和   “公共阴影属性行作为   System.Windows.Forms.DataGridViewRowCollection”无法重载每个   其他,因为它们仅在返回类型上有所不同

我将为在我的Cutsom Control中直接实现威胁安全代码的任何解决方案或其他想法表示感谢。

Public Class XDataGridView
  Inherits System.Windows.Forms.DataGridView

  Private _Rows As XRowCollection
  Public Overrides ReadOnly Property Rows As XRowCollection
    Get
        If _Rows Is Nothing Then
            _Rows = New NoxRowCollection(Me)
        End If
        Return _Rows
    End Get
  End Property
End Class

Public Class XRowCollection
  Inherits DataGridViewRowCollection

  Public Sub New(dataGridView As XDataGridView)
    MyBase.New(CType(dataGridView, DataGridView))
  End Sub

  Private Delegate Sub RowsRemoveCallback(DataGridViewRow As System.Windows.Forms.DataGridViewRow)
  Public Shadows Sub Remove(DataGridViewRow As System.Windows.Forms.DataGridViewRow)
    If MyBase.DataGridView.InvokeRequired Then
        Dim d As New RowsRemoveCallback(AddressOf Remove)
        MyBase.DataGridView.Invoke(d, New Object() {DataGridViewRow})
    Else
        Me.DataGridView.Rows.Remove(DataGridViewRow)
    End If
  End Sub
End Class

0 个答案:

没有答案