Results 1 to 3 of 3

Thread: ListBox I need the help

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    ListBox I need the help

    Hi All

    I have something like this

    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function SendMessage Lib "user32" Alias _
    4.         "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As _
    5.         Long, ByVal wParam As Long, lParam As Any) As Long
    6.  
    7. Const LB_ITEMFROMPOINT = &H1A9
    8.  
    9. Private Sub Form_Load()
    10.   List1.AddItem "Marina"
    11.   List1.AddItem "Phill"
    12.   List1.AddItem "Karla"
    13.   List1.AddItem "Mark"
    14.   List1.AddItem "Antonio"
    15.   List1.AddItem "Theo"
    16.  
    17.   List1.ListIndex = 0
    18. End Sub
    19.  
    20. Private Sub List1_MouseMove(Button As Integer, Shift As Integer, _
    21.                             X As Single, Y As Single)
    22.   Dim P&, LX&, LY&, Param&
    23.      
    24.     LX = List1.Parent.ScaleX(X, List1.Parent.ScaleMode, vbPixels)
    25.     LY = List1.Parent.ScaleY(Y, List1.Parent.ScaleMode, vbPixels)
    26.     Param = CLng(LX) + &H10000 * CLng(LY)
    27.  
    28.     P = SendMessage(List1.hwnd, LB_ITEMFROMPOINT, 0, ByVal Param)
    29.     If P < List1.ListCount Then List1.ListIndex = P
    30. End Sub

    how to switch off procedure (Private Sub List1_MouseMove) after clicking on a chosen an item. I not want after chosen and clicking on a some item to highlight it already other of item in this list.

    Thanks in advance
    I know, I know, my English is bad, sorry .....

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

    Re: ListBox I need the help

    Try something like
    VB Code:
    1. Option Explicit
    2.  
    3. Private blnHasSelected As Boolean
    4.  
    5. Private Declare Function SendMessage Lib "user32" Alias _
    6.         "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As _
    7.         Long, ByVal wParam As Long, lParam As Any) As Long
    8.  
    9. Const LB_ITEMFROMPOINT = &H1A9
    10.  
    11. Private Sub Form_Load()
    12.   List1.AddItem "Marina"
    13.   List1.AddItem "Phill"
    14.   List1.AddItem "Karla"
    15.   List1.AddItem "Mark"
    16.   List1.AddItem "Antonio"
    17.   List1.AddItem "Theo"
    18.  
    19.   List1.ListIndex = 0
    20. End Sub
    21.  
    22. Private Sub List1_Click()
    23. blnHasSelected = True
    24. End Sub
    25.  
    26. Private Sub List1_MouseMove(Button As Integer, Shift As Integer, _
    27.                             X As Single, Y As Single)
    28.   Dim P&, LX&, LY&, Param&
    29.    If blnHasSelected = True The Exit Sub
    30.    
    31.     LX = List1.Parent.ScaleX(X, List1.Parent.ScaleMode, vbPixels)
    32.     LY = List1.Parent.ScaleY(Y, List1.Parent.ScaleMode, vbPixels)
    33.     Param = CLng(LX) + &H10000 * CLng(LY)
    34.  
    35.     P = SendMessage(List1.hwnd, LB_ITEMFROMPOINT, 0, ByVal Param)
    36.     If P < List1.ListCount Then List1.ListIndex = P
    37. End Sub

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    Re: ListBox I need the help

    Hi Hack.
    Thanks for quick reply

    I made a bit in other way, because in this code that you gave me this does not want to work like I want.
    I make it (blnHasSelected = True) in event Mouse_Up because this Click event it happens already in Load event. However I made again the work for this procedure in event Mouse_Move for Form. I seem me that I made it okay. It fine work for me.

    have a look, only in this a bit the code:
    VB Code:
    1. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    2. blnHasSelected = False
    3. End Sub
    4.  
    5. Private Sub List1_MouseMove(Button As Integer, Shift As Integer, _
    6.                             X As Single, Y As Single)
    7.                            
    8.   If blnHasSelected = False Then  '<<< it I changed here on a False
    9.  
    10.     Dim P&, LX&, LY&, Param&
    11.      
    12.     LX = List1.Parent.ScaleX(X, List1.Parent.ScaleMode, vbPixels)
    13.     LY = List1.Parent.ScaleY(Y, List1.Parent.ScaleMode, vbPixels)
    14.     Param = CLng(LX) + &H10000 * CLng(LY)
    15.  
    16.     P = SendMessage(List1.hwnd, LB_ITEMFROMPOINT, 0, ByVal Param)
    17.     If P < List1.ListCount Then List1.ListIndex = P
    18.   End If
    19. End Sub
    20.  
    21. Private Sub List1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    22. blnHasSelected = True
    23. End Sub

    Again very thanks, Hack
    I know, I know, my English is bad, sorry .....

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