这个类如何写?

立早家饰 2007-03-12 07:00:51
Form1中有个Combobox1
我想做到
With ComboBox1
.DataSource = AreaList.Items
.DisplayMember = "Text"
.ValueMember = "Value"
End With
---------------------------------------------
类myList文件中有两个类:myItem、myItems
Public Class myItem
Private ListKey As String
Private ListText As String
Private ListValue As String
Private ListTag As Object

Public Property Key() As String
'省略,都是Get和Set
End Property
Public Property Value() As String
'省略
End Property
Public Property Text() As String
'省略
End Property
Public Property Tag() As Object
'省略
End Property

Public Sub New(ByVal sKey As String, ByVal sText As String, ByVal sValue As String)
ListKey = sKey
ListText = sText
ListValue = sValue
ListTag = Nothing
End Sub

End Class
'##############################
Public Class myItems
'myItem的集合

End Class

请问这个类myItems该怎么写?
要做到 myItems.Item(sKey) 就能找到对应的myItem
...全文
185 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
立早家饰 2007-03-13
  • 打赏
  • 举报
回复
Public Class myItems
'myItem的集合
Inherits System.Collections.DictionaryBase

Public Overloads Sub Add(ByVal theItem As myItem)
If Not Me.Dictionary.Contains(theItem.Key) Then
Me.Dictionary.Add(theItem.Key, theItem)
End If
End Sub
'******************************************************
'Inherits System.Collections.CollectionBase

'Public Sub Add(ByVal theItem As myItem)
' If Not Me.InnerList.Contains(theItem) Then
' Me.InnerList.Add(theItem)
' End If
'End Sub
End Class
在绑定(Combobox1.DataSource = theList)的时候出现错误:复杂的 DataBinding 接受 IList 或 IListSource 作为数据源。
如果把代码改成“*”号低下的样子,即继承CollectionBase,就正确。
请问这是什么原因?如果要继承DictionaryBase的话要怎么改?谢谢!
cangwu_lee 2007-03-12
  • 打赏
  • 举报
回复
System.Collections

看看 msdn
立早家饰 2007-03-12
  • 打赏
  • 举报
回复
上面改一下
Dim theList As myItems
...填充theList...
---------------------------
With ComboBox1
.DataSource = theList
.DisplayMember = "Text"
.ValueMember = "Value"
End With
=====================================
请问怎样直接拿来用?刚学,不太懂
怎样才能做到 theList.Item(sKey)求出对应的myItem
谢谢!
cangwu_lee 2007-03-12
  • 打赏
  • 举报
回复
这几个都是是 .net 的内部对象。

直接拿来用就好了。

myItems 应该是一个数组。

16,718

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧