Results 1 to 9 of 9

Thread: Deselect listitems.

  1. #1

    Thread Starter
    Hyperactive Member Dasiths's Avatar
    Join Date
    Apr 2001
    Location
    Colombo, Sri Lanka
    Posts
    331

    Smile Deselect listitems.

    How can I deselect every selected item in a listbox which has multiple select set to advanced ..
    It is the mark of an instructed mind to rest satisfied with the degree of precision which the nature of the subject admits, and not to seek exactness when only an approximation of the truth is possible.
    -Aristotle As quoted in Rapid Development, chapter 8, page 167.

  2. #2
    jim mcnamara
    Guest
    Code:
      For i = 0 to List1.ListCount -1
        If List1.Selected(i) then
            List1.Selected = False
        End if
      Next i

  3. #3
    Matthew Gates
    Guest
    Originally posted by jim mcnamara
    Code:
      For i = 0 to List1.ListCount -1
        If List1.Selected(i) then
            List1.Selected = False
        End if
      Next i

    The code above is incorrect, you will recieve errors.
    First, you must remove selected items backwards.
    And second, you must tell which item is to be unselected.


    Here is the correct way:


    Code:
    Private Sub Command1_Click()
    
        On Error Resume Next
        Dim i As Integer
        With List1
            For i = .ListCount - 1 To 0 Step -1
                If .Selected(i) Then
                    .Selected(i) = False
                End If
            Next
        End With
    
    End Sub

  4. #4
    jim mcnamara
    Guest
    Matthew is right - you do have to proceed from the bottom up. Other than that, I don't understand the 'Second, ...' idea.

  5. #5
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    JIm...Matthew is being picky..

    you forgot the (x) after selected


    after all he is the "master" LOL!
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  6. #6
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    This should be the best solution without loop throught the entire listitem. But I juz having some problem in the MakeDWord function. which 'coz not all the item being deselected

    Perhpas you guy can help

    Code:
    Option Explicit
    '//WIN32API Function
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    
    '//WIN32API Constant
    Private Const LB_SELITEMRANGE = &H19B
    Private Const LB_SELITEMRANGEEX = &H183
    
    Private Sub Form_Load()
        Dim idx As Long
        For idx = 0 To 50
            List1.AddItem "Item " & idx
        Next
    End Sub
    
    Private Sub Command1_Click()
        Dim ItmRange As Long
        
        Let ItmRange = MakeDWord(0, 50)
        SendMessage List1.hwnd, LB_SELITEMRANGE, 1, ItmRange
    End Sub
    
    Private Sub Command2_Click()
        Dim ItmRange As Long
        
        Let ItmRange = MakeDWord(0, 50)
        SendMessage List1.hwnd, LB_SELITEMRANGE, 0, ItmRange
    End Sub
    
    Function MakeDWord(LoWord As Integer, HiWord As Integer) As Long
        '//This function is generate the DWORD as require for the LB_SELITEMRANGE API constant
        MakeDWord = (HiWord * &H10000) Or (LoWord And &HFFFF&)
    End Function

  7. #7
    AIS_DK
    Guest
    Hey Chris.

    I can't see anything wrong with the way you create the DWord. I have tested it 3 ways now, and it's fine.

    But you are right, it doesn't work. I've tried to change the limits from 0 - 50 to 48 - 50, and it still just highlight element 18 to 50.

    I'm sorry I can't help you anymore then this

    BTW, why are you using:
    Code:
    Let ItmRange = MakeDWord(0, 50)
    Could you not just use:
    Code:
    ItmRange = MakeDWord(0, 50)

  8. #8
    AIS_DK
    Guest
    FOUND IT
    Change the following
    Code:
    SendMessage List1.hwnd, LB_SELITEMRANGE, 1, ItmRange
    to
    Code:
    SendMessage List1.hwnd, LB_SELITEMRANGE, 1, byval ItmRange
    And it works!!!!!!!!!!!

  9. #9
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    wow.. it great! Doesn't realise the ByVal will 'coz the problem.

    Anyway Thanks

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