关于VB的ListBox控件选定项的获取
今天在做VB项目的时候,使用了ListBox控件来获取一些列表项,用了才发现没有ListView好用,ListView有Items(SelectItem)可以定位到当前的选中项,而ListBox没有;ListView有Tag可以设定选中项的标示,ListBox没有。上网也找不到原因,知道去阅读MSDN和自己测试。
之后终于找到了问题的关键。
事件1:添加ListBox项和对应项的标识
Dim List1 As new ListBox
List1.addItem , , 星期一
List1.ItemData(List1.newIndex) = "1"
List1.addItem , , 星期二
List1.ItemData(List1.newIndex) = "2"
List1.addItem , , 星期三
List1.ItemData(List1.newIndex) = "3"
List1.addItem , , 星期四
List1.ItemData(List1.newIndex) = "4"
Private Sub List1_Click()
If List1.ListIndex = -1 Then
Exit Sub '没有选中任何项,退出方法
End If
Debug.Print List1.ItemData(List1.ListIndex) '打印选中的List1的标识。。可能是"1" "2" "3" "4"
Debug.Print List1.Text '打印选中的List1的名称。。可能是星期一到星期四
End Sub
第一次写文章,因为用的上10寸的上网本,写得很简单,如果看不懂请联系我。
刚用ListBox控件,如有哪里不足,请多多指出。谢谢。
相关文档:
'创建快捷方式,兼容vista
'要把vb6stkit.DLL放到程序目录
'敖士伟 09-10-27
'只对“桌面”和“开启”有效,其它还没做
'=========开启外部同步程序定义开始
Const SYNCHRONIZE = &H100000
Const INFINITE = &HFFFF 'Wait forever
Const WAIT_OBJECT_0 = 0 'The state of the spe ......
Function crypt(Action As String, Key As String, Src As String) As String
'Action
' E encrypts, D decrypts,
'Key is a unique string needed to en/decrypt (either
' hardcode or setup something for the user to enter.
'Src is the string to be en/decrypted.
On Error GoTo errHandl ......
帮朋友改的一小段关键词分析代码; 含两个单词复合计数
Private Function CollectWords() As Dictionary(Of String, Integer)
'Create a new dictionary
Dim table As New Dictionary(Of String, Integer)
'Prompt for the user
Console.WriteLine(
"Enter a line : ")
'Get the user's input
Dim input As St ......
如今OCX控件在编程中已占领了很重要的地位,我们可以利用OCX控件完成一些相当复杂的编程操作。同时OCX控件还有利于主程序的简单化、功能的重用、隐藏程序实现细节、便于升级、传播方便等优点。现在我们可以利用VB 5.0方便地制作出自己的OCX控件供我们在编程中使用,同时还可以把它送给你周围喜欢编程的朋友!下面列出制 ......