|
-
May 24th, 2001, 10:36 AM
#1
Thread Starter
Hyperactive Member
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.
-
May 24th, 2001, 10:54 AM
#2
Code:
For i = 0 to List1.ListCount -1
If List1.Selected(i) then
List1.Selected = False
End if
Next i
-
May 24th, 2001, 01:56 PM
#3
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
-
May 24th, 2001, 02:10 PM
#4
Matthew is right - you do have to proceed from the bottom up. Other than that, I don't understand the 'Second, ...' idea.
-
May 24th, 2001, 02:12 PM
#5
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"
-
May 27th, 2001, 08:22 AM
#6
PowerPoster
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
-
May 27th, 2001, 08:51 AM
#7
-
May 27th, 2001, 08:53 AM
#8
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!!!!!!!!!!!
-
May 27th, 2001, 11:20 AM
#9
PowerPoster
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|