473,499 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Select list box's item by right-clicking it?

2 New Member
Hello,
It seems like something simple but I'm still not really able to figure this out.
How can I select a lisbox's item by right-clicking on it?
Thanks in advance for any inputs!
Best regard,
VBNex.
Oct 1 '06 #1
5 2674
CaptainD
135 New Member
Hello,
It seems like something simple but I'm still not really able to figure this out.
How can I select a lisbox's item by right-clicking on it?
Thanks in advance for any inputs!
Best regard,
VBNex.
On the MouseDown, Mouseup event you can check for which button. If Button 2 do something
Oct 1 '06 #2
vbnex
2 New Member
Hello,
Thanks a lot for your answer.
Button number 2,I know but my question was...
What's the code to make the 2nd (right-click) work like the 1st (left mouse button) (To "highlight"/select the entry)?
Thanks!
Oct 1 '06 #3
Cobrasoft
1 New Member
I would like to know that too!!
Nov 14 '06 #4
albertw
267 Contributor
I would like to know that too!!

hi

i might have a solution

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  3.  
  4. Private Const LB_ITEMFROMPOINT = &H1A9
  5. Dim ndx as Long
  6.  
  7.  
  8.  
  9. Public Function ListBoxHit(ListBox As ListBox, ByVal X As Single, ByVal Y As Single) As Long
  10.  
  11.     ndx= SendMessage(YourListBox.hWnd, LB_ITEMFROMPOINT, 0, (Y \ Screen.TwipsPerPixelY) * 65536 + (X \ Screen.TwipsPerPixelX))
  12.     If (ndxAnd &H10000) = &H10000 Then
  13.         ListBoxHit = -1
  14.     Else
  15.         ListBoxHit = ndx
  16.     End If
  17. End Function
  18.  
  19.  
  20. Private Sub YourListBox_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  21.  
  22. If Button = 2 Then
  23.   ndx= ListBoxHit(YourListBox, X, Y)
  24.   If Not ndx= -1 Then YourListBox.Selected(ndx) = True
  25. End If
  26. End Sub
  27.  
  28.  
similar your may alter _mousedown by _mousemove !
:)
Nov 14 '06 #5
Joto
1 New Member
Use the HitTest method:

Expand|Select|Wrap|Line Numbers
  1. Private Sub ListView1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseUp
  2.   Dim hti As ListViewHitTestInfo = ListView1.HitTest(e.Location)
  3.   Dim six As Integer = hti.Item.SubItems.IndexOf(hti.SubItem)
  4.   MsgBox(six.ToString)
  5. End Sub
i didn't test out this exact code, so it might not work exactly, but I know it's this method you want to be using.
Dec 5 '06 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
3808
by: Andrea | last post by:
Hi, I'm trying to emulate part of our client-server application as a web site so customers can use it, and I'm stuck when it comes to re-ordering items in a list. Basically we have a list of...
1
6162
by: Adrian | last post by:
This script works well for searching thru a SELECT list but doesnt work so well with the MULTIPLE option. I need to modify it to work for a SELECT MULTIPLE but I have no idea where to begin, any...
4
11247
by: headware | last post by:
I have a <select> control that contains many entries. It allows the user to multi-select a group of them, click a button, and store the selected data in a database. Normally they do this starting...
19
3508
by: William Wisnieski | last post by:
Hello Everyone, I have a main form with a datasheet subform that I use to query by form. After the user selects two criteria on the main form and clicks the cmdShowResults button on the main...
6
12962
by: Chris Fink | last post by:
Does anyone know it is possible to include a small image(.gif .jpeg) within a <SELECT><option> so that the user would see the option text as well as a little image(icon) in the option? I know this...
1
2988
by: akameswaran | last post by:
I have a list box, I'd like to generate a right click menu for items in the list box. The problem is unless I left click the item first, I can't figure out which item in the list I clicked over. ...
5
1769
by: Bubba | last post by:
I have a dynamic pulldown list (ASP with javascript) that when a user picks a state, the corresponding counties for that state appear in a dynamic second pulldown list. When I submit the form, the...
1
8031
by: The.Daryl.Lu | last post by:
Hi, two parts to my problem if someone can help address either one or both: 1. I want to SELECT everything in the table if it matches the criteria when the query button is pressed (this is just...
1
4008
by: Sunray | last post by:
I have a form called the sales form and i have 2 sets of listboxes So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which...
0
7007
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7220
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7386
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5468
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4918
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4599
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3090
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
664
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
295
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.