vb Listbox 怎样固定选中一项或N项

来源:百度知道 编辑:UC知道 时间:2024/07/07 09:48:30
Dim Atext
Atext = Array("A", "B", "C")
For i = 0 To UBound(Atext)
List1(2).AddItem Atext(i)
List1(2).Selected(i) = True
Next
-------------------------------------
List1(2).MultiSelect=0
想第一项或多项不能被用户改变选中状态
象Enabled=false一样
怎么实现?
Private Sub List1_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
If Index = 2 Then
List1(2).Selected(0) = True
End If
End Sub

这样加就没问题了,就是效果有点逊

这一句语法错误:List1(2).MultiSelect=0,因为MultiSelect属性在运行时是只读的,不能赋值。
应加这么一段:
Private Sub List1_Click(Index As Integer)
If Index = 2 Then
If List1(2).Selected(0) = False Then List1(2).Selected(0) = True
End If
End Sub
以上的List1(2).Selected(0)只是针对你所说的“第一项不能被用户改变选中状态”而言,若是“多项”可以续加代码。

没明白