我發現兩個問題
(1)如果由下方開始框選則沒問題
如果由右方中間開始框選, 先向上選擇幾個, 再向下選擇幾個, 放開滑鼠, 則原向上
方向會多選擇一個, 原因是駐點停留在上方處, 當然反方向操作也是, 我無法解決駐點不反白的問題, 但是檔案總管在框選時, 駐點是不變的, 不會因框選而移動...
(2)Timer1要做到即時顯示選擇數的功能, 但問題是如果資料一多恐怕會影響效率, 不知如何改善?
希望各方高手有空能夠幫我看一下
'請加入 ListView1, Timer1, Label1
Option Explicit
Dim bLVSelectFirst As Boolean
Dim bLVTest1 As Boolean
Dim nLVMouseUpNum As Integer
Dim nCount As Integer
Private Sub Form_Load()
Dim item As ListItem
  
  With ListView1.ColumnHeaders
    .Add , , "", 0, lvwColumnLeft
    .Add , , "N1", 600, lvwColumnLeft
    .Add , , "N2", (ListView1.Width - 700) / 5 * 3, lvwColumnLeft
    .Add , , "N3", (ListView1.Width - 700) / 5 * 2 - 250, lvwColumnLeft
  End With

Randomize Timer
  
  With ListView1
    .GridLines = True
    .HideSelection = False
    .LabelEdit = lvwManual
    .MultiSelect = True
    .FullRowSelect = True
    .View = lvwReport
    .SortOrder = lvwAscending
    .SortKey = 0
    
    For nCount = 1 To 10
      Set item = .ListItems.Add
      item.SubItems(1) = nCount
      item.SubItems(2) = Rnd
      item.SubItems(3) = Rnd
    Next nCount
  End With
End Sub
Private Sub ListView1_ItemClick(ByVal item As MSComctlLib.ListItem)
If bLVSelectFirst = False Then
    item.Selected = True
    bLVSelectFirst = True
  End If
End Sub
Private Sub ListView1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim item As ListItem
  
  If Button = vbLeftButton Then
    bLVTest1 = True
    Timer1.Enabled = True
  Else
    bLVSelectFirst = False
      
    If bLVTest1 Then
      Set item = ListView1.HitTest(x, y)
      
      If Not item Is Nothing Then
        item.Selected = True
        nLVMouseUpNum = item.Index
      End If
    
      bLVTest1 = False
      Timer1.Enabled = False
    End If
  End If
End Sub
Private Sub Timer1_Timer()
Dim nSelectCount As Integer

With ListView1
    If .ListItems.Count = 0 Then Exit Sub

For nCount = 1 To .ListItems.Count
      If .ListItems(nCount).Selected Then
        nSelectCount = nSelectCount + 1
      End If
    Next nCount

Label1 = "已選擇 " & nSelectCount & " 個"
  End With
End Sub
arrow
arrow
    全站熱搜

    vbqa 發表在 痞客邦 留言(5) 人氣()