请教高手:为自定义控件的一个集合属性里面再添加一个集合该如何做,谢谢!!!
有一个自定义控件:有一集合属性:Rows
在窗体中我用:
UserControl11.Rows.Add(5)
UserControl11.Rows.Item(1).Name = "yan"
能设置。我想在Rows中再加一个集合,变成
UserControl11.Rows.Add(5)
UserControl11.Rows.Item(1).Add(5)
UserControl11.Rows.Item(1).Cells(1).Item(1).Name = "yan"
该如何修改代码,谢谢!!!
Imports System.ComponentModel
Public Class UserControl1
Private _coumntscount As Short = 0
<Browsable(True)> _
Public Property Rows As StudentCollectiont
Get
Return _rows
End Get
Set(value As StudentCollectiont)
_rows = value
End Set
End Property
End Class
Public Class Student
Private m_name As String = ""
Public Property Name() As String
Get
Return m_name
End Get
Set(value As String)
m_name = value
End Set
End Property
Private m_id As Integer = 0
Public Property Id() As Integer
Get
Return m_id
End Get
Set(value As Integer)
m_id = value
End Set
End Property
End Class
Public Class StudentCollectiont
Inherits CollectionBase
Public Sub New()
End Sub
Default Public Property Item(index As Integer) As Student
Get
Return DirectCast(List(index), Student)
End Get
Set(value As StudentCollectiontt)
List(index) = value
End Set
End Property
Public Sub Add(value As Integer)
For i As Integer = 1 To value
Dim ffsva As New Student
ffsva.Name=""
ffsva.id=0
List.Add(ffsva)
Next
End Sub
Public Function IndexOf(value As StudentCollectiontt) As Integer
Return (List.IndexOf(value))
End Function
Public Sub Insert(index As Integer, value As StudentCollectiontt)
List.Insert(index, value)
End Sub
Public Sub Remove(value As StudentCollectiontt)
List.Remove(value)
End Sub
Public Function Contains(value As Student) As Boolean
Return (List.Contains(value))
End Function
Protected Overrides Sub OnInsert(index As Integer, value As [Object])
End Sub
Protected Overrides Sub OnRemove(index As Integer, value As [Object])
End Sub
Protected Overrides Sub OnSet(index As Integer, oldValue As [Object], newValue As [Object])
End Sub
Protected Overrides Sub OnValidate(value As [Object])
End Sub
End Class
[解决办法]
vb.net我是没用过,在C#里面我是没有这么用的,根本不用Collectiont,是集合的直接用List<T>,它是个泛型,里面你什么定义都可以,建议你尝试改为List
[解决办法]
Default Public Property Item(index As Integer) As XXXCollection
...
Public Sub Add(value As XXXCollection)
...
再定义一个
Public Class XXXCollection