473,473 Members | 1,953 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

ListBox

Hi!

Could anyone tell me how to select listbox items by right button of the
mouse?
It works originally only with left button.

Thanks.
Nov 15 '05 #1
7 2526
You can use the MouseDown event and check if the button was the right
mouse button

private void listBox1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
if(e.Button == MouseButtons.Right)
{
// right mouse button was clicked
}
}

You probably have to find out which item was "selected".
e.X and e.Y contains the coordinates of the click.

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #2
Thanks for reply Morten !

I've been looking for a little bit simplier solution.

I need such thing to use in the next situation:
user clicks the item and wants to view a context menu, but menu shows
for selected item which is not always the item user clicks by right button
of the mouse.

P.S. retieving wich item was selected by using mouse coordinates looks for
me very hard.

"Morten Wennevik" <Mo************@hotmail.com> ???????/???????? ? ????????
?????????: news:oprxjnygnahntkfz@localhost...
You can use the MouseDown event and check if the button was the right
mouse button

private void listBox1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
if(e.Button == MouseButtons.Right)
{
// right mouse button was clicked
}
}

You probably have to find out which item was "selected".
e.X and e.Y contains the coordinates of the click.

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #3
There is no other way. You have to analyze where right-click was done.

And it's not really hard. Take a look at IndexFromPoint method.

HTH
Alex

"Dmitry Karneyev" <ka******@msn.com> wrote in message
news:uf**************@TK2MSFTNGP10.phx.gbl...
Thanks for reply Morten !

I've been looking for a little bit simplier solution.

I need such thing to use in the next situation:
user clicks the item and wants to view a context menu, but menu shows
for selected item which is not always the item user clicks by right button
of the mouse.

P.S. retieving wich item was selected by using mouse coordinates looks for
me very hard.

"Morten Wennevik" <Mo************@hotmail.com> ???????/???????? ? ????????
?????????: news:oprxjnygnahntkfz@localhost...
You can use the MouseDown event and check if the button was the right
mouse button

private void listBox1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
if(e.Button == MouseButtons.Right)
{
// right mouse button was clicked
}
}

You probably have to find out which item was "selected".
e.X and e.Y contains the coordinates of the click.

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/

Nov 15 '05 #4
Hi,

I think it's not THAT difficult, take a look at ListBox.GetItemRectangle()
it may be a little performance poor as you have to iterate in the list but I
think that it can be done

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Dmitry Karneyev" <ka******@msn.com> wrote in message
news:uf**************@TK2MSFTNGP10.phx.gbl...
Thanks for reply Morten !

I've been looking for a little bit simplier solution.

I need such thing to use in the next situation:
user clicks the item and wants to view a context menu, but menu shows
for selected item which is not always the item user clicks by right button
of the mouse.

P.S. retieving wich item was selected by using mouse coordinates looks for
me very hard.

"Morten Wennevik" <Mo************@hotmail.com> ???????/???????? ? ????????
?????????: news:oprxjnygnahntkfz@localhost...
You can use the MouseDown event and check if the button was the right
mouse button

private void listBox1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
if(e.Button == MouseButtons.Right)
{
// right mouse button was clicked
}
}

You probably have to find out which item was "selected".
e.X and e.Y contains the coordinates of the click.

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/

Nov 15 '05 #5
I think about next variant:
maybe it is possible to intercept mouse clicks events and to redirect them
with other properties.
I mean intercept button clicks analyze which button was clicked and if it
was right button - raise 2 events:
1. all properties the same without "button number"
2. the same event to display context menu.

What do you think guys about it?

"AlexS" <sa***********@SPAMsympaticoPLEASE.ca> ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ
ÓÌÅÄÕÀÝÅÅ: news:ev**************@TK2MSFTNGP09.phx.gbl...
There is no other way. You have to analyze where right-click was done.

And it's not really hard. Take a look at IndexFromPoint method.

HTH
Alex

"Dmitry Karneyev" <ka******@msn.com> wrote in message
news:uf**************@TK2MSFTNGP10.phx.gbl...
Thanks for reply Morten !

I've been looking for a little bit simplier solution.

I need such thing to use in the next situation:
user clicks the item and wants to view a context menu, but menu shows
for selected item which is not always the item user clicks by right button of the mouse.

P.S. retieving wich item was selected by using mouse coordinates looks for me very hard.

"Morten Wennevik" <Mo************@hotmail.com> ???????/???????? ? ???????? ?????????: news:oprxjnygnahntkfz@localhost...
You can use the MouseDown event and check if the button was the right
mouse button

private void listBox1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
if(e.Button == MouseButtons.Right)
{
// right mouse button was clicked
}
}

You probably have to find out which item was "selected".
e.X and e.Y contains the coordinates of the click.

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/


Nov 15 '05 #6
Well, actually your variant is rather good!
I'll use it.

Thanks.

"AlexS" <sa***********@SPAMsympaticoPLEASE.ca> ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ
ÓÌÅÄÕÀÝÅÅ: news:ev**************@TK2MSFTNGP09.phx.gbl...
There is no other way. You have to analyze where right-click was done.

And it's not really hard. Take a look at IndexFromPoint method.

HTH
Alex

"Dmitry Karneyev" <ka******@msn.com> wrote in message
news:uf**************@TK2MSFTNGP10.phx.gbl...
Thanks for reply Morten !

I've been looking for a little bit simplier solution.

I need such thing to use in the next situation:
user clicks the item and wants to view a context menu, but menu shows
for selected item which is not always the item user clicks by right button of the mouse.

P.S. retieving wich item was selected by using mouse coordinates looks for me very hard.

"Morten Wennevik" <Mo************@hotmail.com> ???????/???????? ? ???????? ?????????: news:oprxjnygnahntkfz@localhost...
You can use the MouseDown event and check if the button was the right
mouse button

private void listBox1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
if(e.Button == MouseButtons.Right)
{
// right mouse button was clicked
}
}

You probably have to find out which item was "selected".
e.X and e.Y contains the coordinates of the click.

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/


Nov 15 '05 #7
If I understand you correct you can do that by adding common stuff before
checking for mouse button.

private void listBox1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
// do common stuff

if(e.Button == MouseButtons.Right)
{
// show context menu
}
}

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #8

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)...
3
by: Paul T. Rong | last post by:
I have a listbox (of product names) control on my form. I want to pass the selected item (a product name) to a subform, and the product unitprice should apear automatically next to the product name...
8
by: Oddball | last post by:
Ok - I have a ListBox control and I'm ready to write my own DrawItem event handler. What I want to draw as the item is another control. I have created a user control that I would like to list in...
2
by: collie | last post by:
Hi, I have 2 listboxes. The first gets populated from the db as soon as the page loads. The second listbox get populated based on the user's selection from the first listbox. However,...
6
by: Chris Leuty | last post by:
I am populating a multiselect Listbox from a dataset, with the content of the listbox filled by one table, and the selections determined from another table. So far, I have been keeping the dataset...
1
by: yamne | last post by:
I have a problem. When I click in edit datagrid button I show two listbox and two button. I use two button to move data between two listbox. My problem is that I can't call the listbox in the...
7
by: Dave | last post by:
Hi all, After unsuccessfully trying to make my own dual listbox control out of arraylists, I decided to look for a 3rd party control. I've looked for over a week now and can't find anything but...
3
by: Ali Chambers | last post by:
Hi, I have created a listbox called "dtlist1" on my VB.NET form. I call a procedure as follows: Private Sub openfile(flname As String) dtlist1.Items.Clear() etc..
1
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...
5
by: Academia | last post by:
(If you've seen this in the drawing NG, sorry. I inadvertently sent it there.) I have a listbox populated with Objects. The Class has a String field that ToString returns. I assume that...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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
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,...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.