Results 1 to 10 of 10

Thread: counting listview selected

  1. #1

    Thread Starter
    Registered User
    Join Date
    Sep 2002
    Posts
    221

    counting listview selected

    Is it possible to count the number of files in listview as they are being selected when you draw the dotted box using the mouse in the listview

    e.g. as soon as a file in the listview goes blue when the dotted box created with the mouse goes over it. is it possible to count the number of files selected and put the value into a text box.

    does anyone know how to do this???

  2. #2
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    Probably not the most accurate, but you can put code like this in your mousemove event:
    VB Code:
    1. Private Sub ListView_MouseMove(some arguments here)
    2. Dim TotalSel As Long
    3. For i = 1 To ListView.ListItems.Count
    4.   If ListView.ListItems(i).Selected = True Then
    5.     TotalSel = TotalSel + 1
    6.   End If
    7. Next
    8. End Sub
    <removed by admin>

  3. #3
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
    4.                                                                         ByVal wMsg As Long, _
    5.                                                                         ByVal wParam As Long, _
    6.                                                                         lParam As Any) _
    7.                                                                         As Long
    8.  
    9. Private Const LVM_FIRST = &H1000
    10. Private Const LVM_GETSELECTEDCOUNT = (LVM_FIRST + 50)
    11.  
    12. Private Sub Command1_Click()
    13.     MsgBox SendMessage(ListView1.hwnd, LVM_GETSELECTEDCOUNT, 0&, 0&)
    14. End Sub

    Untested, but try it.

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    crptcblade' solution is the easiest, and the one I would suggest, but if you are going to go the MidgetsBro's route, the If/End If syntax needs to be changed slightly in order to work.
    VB Code:
    1. Private Sub ListView1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
    2. Dim i As Long
    3. Dim TotalSel As Long
    4. For i = 1 To ListView1.ListItems.Count
    5.     If ListView1.ListItems.Item(i).Selected = True Then
    6.        TotalSel = TotalSel + 1
    7.     End If
    8. Next  
    9. End Sub

  5. #5
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    Originally posted by crptcblade
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
    4.                                                                         ByVal wMsg As Long, _
    5.                                                                         ByVal wParam As Long, _
    6.                                                                         lParam As Any) _
    7.                                                                         As Long
    8.  
    9. Private Const LVM_FIRST = &H1000
    10. Private Const LVM_GETSELECTEDCOUNT = (LVM_FIRST + 50)
    11.  
    12. Private Sub Command1_Click()
    13.     MsgBox SendMessage(ListView1.hwnd, LVM_GETSELECTEDCOUNT, 0&, 0&)
    14. End Sub

    Untested, but try it.

    how can you tell what messages you can send to an objects handle... is there documentation on what windows messages a listview will accept? I mean how would one figure this out? I trust that you didn't guess this up yourself..

  6. #6
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Originally posted by kleinma
    how can you tell what messages you can send to an objects handle... is there documentation on what windows messages a listview will accept? I mean how would one figure this out? I trust that you didn't guess this up yourself..
    msdn.microsoft.com

    For some reason these guys seem to know a hell of a lot of stuff.

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  7. #7
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    Win32 API book by Dan Appelman is a very good source, but most of the time I personally do lots of researches: MS site is one of them. Most of the information is for C programmers (happend I do know C) but even you don't know it - it'll give general info that is simple enough to convert.
    Roy

  8. #8
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    Originally posted by crptcblade
    msdn.microsoft.com

    For some reason these guys seem to know a hell of a lot of stuff.

    i use the MSDN from time to time.. but i find it has SOOO much info that you often get lost looking for a simple answer...

  9. #9
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Originally posted by kleinma
    i use the MSDN from time to time.. but i find it has SOOO much info that you often get lost looking for a simple answer...
    Yeah, most of the time you really need to know what you are looking for, which kind of defeats the purpose, I guess.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  10. #10
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    For ListView specific stuff, download this .BAS file


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width