473,387 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Hittest on listbox?

Hi all,

I'm trying to correct the (imho) wrong behaviour of a listbox when the user
right-clicks on an item. I would like the selection to change when this
happens, just like when the user uses the left mouse button.
Most multi-item controls seem to have the hittest method, but in the
documentation of the listbox I can't find it.

Does anyone know how to do this?

Tia,
Martin
Mar 12 '06 #1
2 10386
"Martin" <x@y.com> schrieb:
I'm trying to correct the (imho) wrong behaviour of a listbox when the
user right-clicks on an item. I would like the selection to change when
this happens, just like when the user uses the left mouse button.
Most multi-item controls seem to have the hittest method, but in the
documentation of the listbox I can't find it.


\\\
Private Sub ListBox1_MouseUp( _
ByVal sender As Object, _
ByVal e As MouseEventArgs _:
) Handles ListBox1.MouseUp
If e.Button = MouseButtons.Right Then
Dim n As Integer = Me.ListBox1.IndexFromPoint(e.X, e.Y)
If n <> ListBox.NoMatches Then
Me.ListBox1.SelectedIndex = n

' Show context menu here using 'ContextMenu.Show'...
End If
End If
End Sub
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Mar 12 '06 #2
Brilliant! Thanks a lot.

Martin

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:uu**************@TK2MSFTNGP09.phx.gbl...
"Martin" <x@y.com> schrieb:
I'm trying to correct the (imho) wrong behaviour of a listbox when the
user right-clicks on an item. I would like the selection to change when
this happens, just like when the user uses the left mouse button.
Most multi-item controls seem to have the hittest method, but in the
documentation of the listbox I can't find it.


\\\
Private Sub ListBox1_MouseUp( _
ByVal sender As Object, _
ByVal e As MouseEventArgs _:
) Handles ListBox1.MouseUp
If e.Button = MouseButtons.Right Then
Dim n As Integer = Me.ListBox1.IndexFromPoint(e.X, e.Y)
If n <> ListBox.NoMatches Then
Me.ListBox1.SelectedIndex = n

' Show context menu here using 'ContextMenu.Show'...
End If
End If
End Sub
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Mar 12 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: amber | last post by:
Hello. Can someone tell me what I may be doing wrong here? I'm using the code (lboxRP is a listbox): Dim newRPindex As Integer newRPindex = Me.lboxRP.FindString(RP)...
0
by: luckybird | last post by:
I succeeded in obtaining a CListCtrl item info using HitTest() when the List Ctrl is owned by my current thread. But when I tried HitTest an item of a List Ctrl owned by other threads such as...
1
by: H.B. | last post by:
Hi, I get LVHITTESTINFO::Flag=LVHT_NOWHERE when I do a Hit Test in my ListView. The list containts items and subitems created with designer. Clicking anywhere in the list makes not HitTest...
3
by: Maria Anthonsen | last post by:
I'm using HitTest to get a value from the cells into a textbox. I have put the HitTest code into the MouseDown-event, and everything is working except one thing. When I start the program the value...
0
by: ohadasor | last post by:
Hi All, I have a listview, which has a vertical scrollbar so not all items are visible at the same time. I have the coordinate of a point for which I need to know which one of the ListViewItems...
2
by: Piotrekk | last post by:
Hi. I have a trackbar. I need to set trackbar value depending on where user has clicked on the bar ( mouse_up event for example ). However avent arguments are telling me only about x and y...
1
by: =?Utf-8?B?cG1jZ3VpcmU=?= | last post by:
I'm trying to use the Hittest to determine where on a node my mouse is. Only I want to know stuff for which there isn't a flag -- eg "Is the hit in the upper part, the center, or the bottom part...
0
by: Gotch | last post by:
Hi, I'm using VisualTreeHelper.HitTest in the following situation: I have a grid, that I use to position a certain number of labels. When the user clicks on one of these labels they won't be able...
2
by: =?Utf-8?B?UGFycm90?= | last post by:
I am trying to implement a drag and drop operation from a listbox to a data gridview control but I keep getting -1 for my row index when the dragdrop function is executed. Below is my coding. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...

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.