|
-
May 9th, 2006, 11:15 PM
#1
Thread Starter
Junior Member
[RESOLVED] Highlight a listbox entry-NO click event
Hello,
I have a listbox, and I am using a SendMessage API call in the MouseMove event in order to get the index of the list item over which the cursor is hovering. I then want to highlight that item in the list, but WITHOUT sending a click event. Currently, I use the folllowing code...
VB Code:
List1.Selected(index) = true
Whereas, that does highlight the listbox entry (index), it also sends a click event, which i do not want to do until the end user actually clicks the mouse.
-
May 9th, 2006, 11:26 PM
#2
Re: Highlight a listbox entry-NO click event
I don't think what you're after is possible to achieve. You might have to consider moving your selection handler logic to the MouseUp event instead (I hope that exists).
-
May 9th, 2006, 11:33 PM
#3
Thread Starter
Junior Member
Re: Highlight a listbox entry-NO click event
Penagate,
Thanks for the reply, but let me explain further. If I have a list box with 8 items in it, as I hover down the list, I want the current selection to be highlighted, but I do not want to automatically fire off the click event just because I am hovering over the 1st item in the list. This is a very common application...actually, I'm quite frustrated that I can't figure it out, because it shouldn't be that difficult to do after you've retrieved the list index.
-
May 9th, 2006, 11:39 PM
#4
Re: Highlight a listbox entry-NO click event
How about just setting a public flag that causes the click event to be ignored, like this
VB Code:
'
' Get the index of the item under the mouse cursor
'
idx = SendMessage(LB.hwnd, LB_ITEMFROMPOINT, 0, ByVal xyPos)
'
' Cause the list box highlight to follow the mouse
'
bIgnoreClick = True ' Tell the list box to ignore the click event
LB.ListIndex = idx
bIgnoreClick = False
And then in the list box's click event
VB Code:
Private Sub List1_Click()
If bIgnoreClick Then
Exit Sub
End If
End Sub
Not very 'techy', but it works just fine.
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
May 9th, 2006, 11:39 PM
#5
Re: Highlight a listbox entry-NO click event
Do you actually need the item you are hovering over to be selected? Or are you simply after a highlight effect?
If the latter is what you want, I would suggest moving to a ListView control, which provides a HotTracking (or something) property. That will give you a highlight effect without actually selecting items as you move the mouse.
-
May 9th, 2006, 11:46 PM
#6
Thread Starter
Junior Member
Re: Highlight a listbox entry-NO click event
pnish,
Thanks for the reply. You're right, it's "low-tech", but it works...lol.
-
May 9th, 2006, 11:48 PM
#7
Thread Starter
Junior Member
Re: Highlight a listbox entry-NO click event
Penagate,
It is only the highlight effect I want, until the user clicks the mouse; only then, do I want the click event to engage. I'll take a look at the listview control...thanks.
-
May 9th, 2006, 11:52 PM
#8
Fanatic Member
Re: Highlight a listbox entry-NO click event
This should not fire the ListBox's click event...
VB Code:
Private Const LB_SETSEL = &H185&
Call SendMessage(ListBox.hWnd, LB_SETSEL, True, ByVal index)
-
May 10th, 2006, 12:04 AM
#9
Thread Starter
Junior Member
Re: Highlight a listbox entry-NO click event
Hi Daydee,
Thanks for the reply. It did not fire the click event, however, it dit not highlight the items in the listbox either.
-
May 10th, 2006, 12:19 AM
#10
Fanatic Member
Re: Highlight a listbox entry-NO click event
Ok I forgot to mention that you need to have the listBox's MultiSelect property set to Simple or Extended for this to work.
BTW, this is exactly what I needed once too.
Here's basically how I acheived it using a listbox with multiSelect = 1
VB Code:
Private Declare Function LBItemFromPt Lib "comctl32.dll" (ByVal hLB As Long, ByVal ptx As Integer, ByVal pty As Integer, ByVal bAutoScroll As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
Private tPos As POINTAPI
Private Const LB_SETSEL = &H185&
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
Private Sub List1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim index As Long
Call SendMessage(List1.hWnd, LB_SETSEL, False, ByVal -1)
GetCursorPos tPos
index = LBItemFromPt(List1.hWnd, tPos.X, tPos.Y, 0)
Call SendMessage(List1.hWnd, LB_SETSEL, True, ByVal index)
End Sub
Cheers!
-
May 10th, 2006, 02:36 PM
#11
Thread Starter
Junior Member
Re: Highlight a listbox entry-NO click event
Daydee,
Thanks a million...works perfectly!
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
|