| 网站首页 | JAVA文章 | AppServers | Web开发 | 应用开发 | 资源下载 | 论坛
    想学好编程,学好外语很重要  [enadd  2006年12月25日]        
设为首页 加入收藏 联系站长
您现在的位置: 编程笔记网 >> 应用开发 >> vb >> 控件 >> 文章正文
使两个ListBox项目同步            【字体:
使两个ListBox项目同步
作者:-    文章来源:-    点击数:    更新时间:2006-6-10

使List1项目的移动、选取,影响List2项目的动、选取

需:两个ListBox,一个Timer
但这是vb4.0的作法,在vb5.0时,可以由Thomasaria 提供的简易作法完成

Private Sub List1_Scroll(Index As Integer)
'按卷动轴时list项目位置同步
List2.TopIndex = List1.TopIndex
End Sub

Private Sub List2_Scroll(Index As Integer)
'按卷动轴时list项目位置同步
List1.TopIndex = List2.TopIndex
End Sub


Option Explicit

Sub Form_Load()
      'Initialize two list boxes with the alphabet
      Dim i As Long
      For i = 1 To 26
	 List1.AddItem Chr$(i + 64)
      Next i
      For i = 1 To 26
	 List2.AddItem Chr$(i + 64)
      Next i
      Timer1.Interval = 1
      Timer1.Enabled = True
End Sub

Sub Timer1_Timer()
      Dim TopIndex_List1 As Long
      Static PrevTI_List1
      'Get the index for the first item in the visible list
      TopIndex_List1 = List1.TopIndex
      'See if the top index has changed
      If TopIndex_List1 <> PrevTI_List1 Then
	 'Set the top index of List2 equal to List1 so that the list boxes
	 'scroll to the same relative position
	 List2.TopIndex = TopIndex_List1
	 'Keep track of the current top index
	 PrevTI_List1 = TopIndex_List1
      End If
      'Select the item in the same relative position in both list boxes
      If List1.ListIndex <> List2.ListIndex Then
	 List2.ListIndex = List1.ListIndex
      End If
End Sub

[1]

文章录入:enadd    责任编辑:enadd 
  • 上一篇文章:

  • 下一篇文章:
  • 发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    最新热点 最新推荐 相关文章
  • 用VB编写DirectX7.0游戏(下…

  • 用VB编写DirectX7.0游戏(上…

  • 使用OLE DB和ADO调用返回记录…

  • 使用VB调用Oracle程序包内的…

  • VB中用ADO对象动态创建数据库…

  • fffff

  • 如何用MSComm Control传Bina…

  • MultiLink的WinSock Server程…

  • 用VB制作浏览器

  • 用VB编写网络寻呼机

  •   网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
    | 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 版权申明 | 管理登录 |