关于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控件,如有哪里不足,请多多指出。谢谢。
相关文档:
http://zhidao.baidu.com/question/81532606.html
VB 读指定行
悬赏分:10 - 解决时间:2009-1-20 11:41
vb中如何读取指定行的内容,窗体上有两个标签,文件在C:\A.TXT,四个按钮,单击第一个,读文件的第一行到标签一,第二行到标签二;单击第二个按钮,第三行到标签一,第四行到标签二;以此类推,谢谢
提问者: im ......
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 ......
Visual Basic有着强大的数据库存取能力,不仅能够直接支持Ms Access数据库,而且通过其内部安装的ISAM驱动程序使它能间接支持FoxPro、dBASE等外来数据库。本文不仅从VB数据库体系结构的角度探索了VB对这些外来数据库的支持,还结合了一些实例具体阐述了使用数据库存取对象变量的方法实现这些外来数据库的新建、库结构修改、 ......
把鼠标移到屏幕指定位置 如(111.111) 单击一下
再移到屏幕另一指定位置指定位置 如(222.222)单击一下
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Declare Function SetCursorPo ......