首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

怎么实现用数组替代listbox控件

2012-08-16 
如何实现用数组替代listbox控件?一般情况下,直接拖个控件很好用很方便.但是还是有些场合,比如想做成模块,

如何实现用数组替代listbox控件?
一般情况下,直接拖个控件很好用很方便.但是还是有些场合,比如想做成模块,还是会需要零控件(又如.net中用多线程时,用控件就有跨线程调用窗体控件的问题,很麻烦.).因此想用数组来替代.
listbox很好用,比如.addItem方法,比如去重. 而数组是定长的,在变长情况下,好像没有list好用。数组要怎么实现类似listbox的.addItem方法和去重呢?数组好像没有.add方法.
比如下面这个代码,如果不想用list,而改用数组的话,怎么来实现呢?多谢!!

VB code
dim i as integerfor i = 0 to 10list1.addItem inext i   Dim j As Integer   Dim p As Integer        With ListBox1            For j = 0 To .listCount - 1                For p = .listCount - 1 To j + 1 Step -1                    If .list(p) = .list(j) Then                        .Remove(p)                    End If                Next p            Next j        End With


[解决办法]
用字典 Dictionary 试试
[解决办法]
http://support.microsoft.com/kb/187234/zh-cn
[解决办法]
探讨
找到个代码 用dictionary的.
请教下如果我要用去重后的数据刷新原数组 应该要怎么写呢?

VB code
dim dic as dictionary
Set dic = New Dictionary
For i = 0 To ubound(a)
If Not dic.Exists(a(i)) Then
dic.Ad……

热点排行