-
December 21st, 2009, 08:53 AM
#1
[RESOLVED] raising an event
Hello.
I have a listbox. And I want to select the proper item when the user right-clicks an item. An ideea I had was to use MouseDown event because the item is selected when the left mouse button is down, but I DON'T KNOW how to do that.
Can you please help me?
-
December 21st, 2009, 09:21 AM
#2
Re: raising an event
the listbox raises the mousedown event and you only have to attach an event handler. you don't know how to do it? you should read about events in c#.
win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming
remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation
private lessons are not an option so please don't ask for help in private, I won't replay
if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know
-
December 21st, 2009, 10:08 AM
#3
Re: raising an event
Originally Posted by Feoggou
Hello.
I have a listbox. And I want to select the proper item when the user right-clicks an item. An ideea I had was to use MouseDown event because the item is selected when the left mouse button is down, but I DON'T KNOW how to do that.
Can you please help me?
I would also add that the item in the listbox is selected when click it with the left mouse button. That is the behaviour of the list box. You don't need to do anything to get that to work. The event is raised for you as explained by mememoo and you can add a handler for it easily. So the question becomes why do you need right mouse button click? Normally that is used for context menus that pop up...Is this the case with you?
-
December 21st, 2009, 10:41 AM
#4
Re: raising an event
Originally Posted by nelo
So the question becomes why do you need right mouse button click?
well, I need to use a context menu for the menuitem that is underneath the cursor (that is, the cursor is above that menuitem). it is odd to always left-click and right click to have the needed item selected (the context menu is for the menuitem, not for the listbox as a whole).
-
December 21st, 2009, 10:55 AM
#5
Re: raising an event
Code:
private void listBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
this.listBox1.SelectedIndex = this.listBox1.IndexFromPoint(e.Location);
}
win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming
remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation
private lessons are not an option so please don't ask for help in private, I won't replay
if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know
-
December 21st, 2009, 11:00 AM
#6
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
|