在vb中如何用程序表达listbox中被选中的项目
List1.ListIndex>=0这个好像不行,Setrs=NewRecordsetIfList1.SelCount>=2ThenMsgBox"请先在列表中选择某字段"...
List1.ListIndex >= 0这个好像不行,
Set rs = New Recordset
If List1.SelCount >= 2 Then
MsgBox "请先在列表中选择某字段", , "注意"
Else
For i = 0 To List1.ListCount - 1
If List1.Selected(i) = True Then
gnbmTmp = Left(List1.List(i), 2)
End If
Next
MsgBox gnbmTmp
sqltmp1 = "select * from SBGNDY where gnbm in (" & gnbmTmp & ") "
rs.Open sqltmp1, g_Cnstr
If Not rs.EOF Then a = rs("sbbm")
For i = 1 To Len(a) Step 3
sbbmTmp = Mid(a, i, 3)
i = i + 3
Next i
sqltmp1 = "select * from SBXX where sbbm in (" & sbbmTmp & ") and statue='free'"
datPrimaryRS.RecordSource = sqltmp1
datPrimaryRS.CommandType = adCmdText
datPrimaryRS.Refresh
DataGrid1.Refresh
End If
这个程序的目的:根据选中的gnbm查找到sbbm,假如sbbm位111222时无法输出222对应的设备信息。帮帮忙!马上毕业,老师不管,我有不太会用vb。 展开
Set rs = New Recordset
If List1.SelCount >= 2 Then
MsgBox "请先在列表中选择某字段", , "注意"
Else
For i = 0 To List1.ListCount - 1
If List1.Selected(i) = True Then
gnbmTmp = Left(List1.List(i), 2)
End If
Next
MsgBox gnbmTmp
sqltmp1 = "select * from SBGNDY where gnbm in (" & gnbmTmp & ") "
rs.Open sqltmp1, g_Cnstr
If Not rs.EOF Then a = rs("sbbm")
For i = 1 To Len(a) Step 3
sbbmTmp = Mid(a, i, 3)
i = i + 3
Next i
sqltmp1 = "select * from SBXX where sbbm in (" & sbbmTmp & ") and statue='free'"
datPrimaryRS.RecordSource = sqltmp1
datPrimaryRS.CommandType = adCmdText
datPrimaryRS.Refresh
DataGrid1.Refresh
End If
这个程序的目的:根据选中的gnbm查找到sbbm,假如sbbm位111222时无法输出222对应的设备信息。帮帮忙!马上毕业,老师不管,我有不太会用vb。 展开
2个回答
展开全部
For i = 1 To List1.ListItems.Count
'逐条判断是否被选中,如果选中,得到该项目
If List1.ListItems(i).Selected = True Then
strItem = List1.ListItems(i)
end if
next
'逐条判断是否被选中,如果选中,得到该项目
If List1.ListItems(i).Selected = True Then
strItem = List1.ListItems(i)
end if
next
更多追问追答
追问
For i = 0 To List1.ListCount - 1
If List1.ListIndex >= 0 Then
s = s + 1
End If
Next
我想判断是否为一个选定项,如果多于两个,我想出现提示,你看我这如何修改
追答
前面回答的是ListView控件,我看错了。
ListBox可以用List1.SelCount得到选定了多少项。
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Dim s
Private Sub Form_Click()
Dim c As Long
c = GetSelCount()
If c = 0 Then
MsgBox "一个都没选中!"
Exit Sub
End If
If c = 1 Then
MsgBox "选中一个!"
Else
MsgBox "选中了多个!"
End If
End Sub
Private Sub Form_Load()
For i = 0 To 10
List1.AddItem "test" & CStr(i)
Next
End Sub
Function GetSelCount() As Long
s = ""
For i = 0 To List1.ListCount - 1
If List1.Selected(i) Then
s = s & " " & CStr(i)
End If
Next
s = Trim(s)
If s = "" Then
'一个都没选中
GetSelCount = 0
Else
s = Split(s)
GetSelCount = UBound(s) + 1
End If
End Function
Private Sub Form_Click()
Dim c As Long
c = GetSelCount()
If c = 0 Then
MsgBox "一个都没选中!"
Exit Sub
End If
If c = 1 Then
MsgBox "选中一个!"
Else
MsgBox "选中了多个!"
End If
End Sub
Private Sub Form_Load()
For i = 0 To 10
List1.AddItem "test" & CStr(i)
Next
End Sub
Function GetSelCount() As Long
s = ""
For i = 0 To List1.ListCount - 1
If List1.Selected(i) Then
s = s & " " & CStr(i)
End If
Next
s = Trim(s)
If s = "" Then
'一个都没选中
GetSelCount = 0
Else
s = Split(s)
GetSelCount = UBound(s) + 1
End If
End Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询