473,327 Members | 1,930 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,327 software developers and data experts.

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 2522
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you▓ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: ShФllНpТpО 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.