CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2006
    Location
    Timisoara, Romania
    Posts
    433

    [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?

  2. #2
    Join Date
    Oct 2008
    Location
    Cologne, Germany
    Posts
    756

    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

  3. #3
    Join Date
    Nov 2002
    Location
    .NET 3.5 VS2008
    Posts
    1,039

    Re: raising an event

    Quote Originally Posted by Feoggou View Post
    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?

  4. #4
    Join Date
    Aug 2006
    Location
    Timisoara, Romania
    Posts
    433

    Re: raising an event

    Quote 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).

  5. #5
    Join Date
    Oct 2008
    Location
    Cologne, Germany
    Posts
    756

    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

  6. #6
    Join Date
    Aug 2006
    Location
    Timisoara, Romania
    Posts
    433

    Re: raising an event

    thanks a lot.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured