1
我有一個名爲UIGrid控制它從DataGridView
現在繼承,我想從DataGridViewRowCollection行物業類型更改爲UIGridRowCollection
我已經過載行屬性返回我喜歡的類型但它不工作,因爲我想 我需要,當我爲網格設置一個數據源,它添加了UIGridRow對象,而不是DataGridViewRow
我怎麼能做到這一點?
注:控制在45項目中的解決方案中使用,所以我不能改變的第三方解決方案繼承的DataGridView和改變行鍵入
這裏是一個示例代碼:
Public Class UIGrid : Inherits DataGridView
Private _Rows As UIGridRowCollection
Public Overloads ReadOnly Property Rows As UIGridRowCollection
Get
If _Rows Is Nothing Then
_Rows = New UIGridRowCollection(Me)
End If
Return _Rows
End Get
End Property
End Class
Public Class UIGridRow : Inherits DataGridViewRow
Public Property ChildControl As Control
End Class
Public Class UIGridRowCollection : Inherits DataGridViewRowCollection
Public Sub New(grid As UIGrid)
MyBase.New(CType(grid, DataGridView))
End Sub
Public Overloads Function Add(row As UIGridRow) As Integer
Return MyBase.Add(row)
End Function
End Class
現在,當我嘗試使用UIGrid控件並向它添加行,我面臨錯誤:
提供的行索引超出範圍。 示例代碼:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.UiGrid1.Columns.Add("Id", "Id")
Me.UiGrid1.Columns.Add("Name", "Name")
For i As Integer = 1 To 10
Dim row As New UIGridRow
row.CreateCells(Me.UiGrid1)
row.Cells(0).Value = i
row.Cells(1).Value = "Employee " & i.ToString
Me.UiGrid1.Rows.Add(row)
Next
End Sub
當我將DataSource屬性設置爲網格,行屬性仍計數0,如此看來,網格不使用重載的行物業
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim dt As New DataTable
dt.Columns.Add("Id", GetType(Integer))
dt.Columns.Add("Name", GetType(String))
For i As Integer = 1 To 10
dt.Rows.Add(i, "Name " & i)
Next
Me.UiGrid1.DataSource = dt
End Sub
我需要當我使用DataSource屬性時,網格使用重載的行屬性,並添加行的類型UIGridRow而不是DataGridViewRow
什麼建議嗎? – Mahdy 2013-05-07 11:28:58