龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > VB开发 >

使两个列表框(ListBox)的选项同步

时间:2009-12-30 15:42来源:未知 作者:admin 点击:
分享到:
1. 在 Form 中添加两个 ListBox 和一个 CommandButton 一个 Timer, 不要改动他们的属性。 2. 在 Form 中添加以下代码: Private Sub Form_Load() Dim X As Integer For X = 1 To 26 List1.AddItem Chr$(X + 64) Next X For X =

1. 在 Form 中添加两个 ListBox 和一个 CommandButton 一个 Timer, 不要改动他们的属性。

2. 在 Form 中添加以下代码:

Private Sub Form_Load()
Dim X As Integer
For X = 1 To 26
List1.AddItem Chr$(X + 64)
Next X
For X = 1 To 26
List2.AddItem Chr$(X + 64)
Next X
Timer1.Interval = 1
Timer1.Enabled = True
End Sub
Private Sub Command1_Click()
End
End Sub
Private Sub timer1_Timer()
Static PrevList1
Dim TopIndex_List1 As Integer
TopIndex_List1 = List1.TopIndex
If TopIndex_List1 <> PrevList1 Then
List2.TopIndex = TopIndex_List1
PrevList1 = TopIndex_List1
End If
If List1.ListIndex <> List2.ListIndex Then
List2.ListIndex = List1.ListIndex
End If
End Sub

运行程序,当选中其中一个列表框中的某一项后,另外一个列表框中的相应项就会被选中。

精彩图集

赞助商链接