Results 1 to 3 of 3

Thread: Right-CLick for Select

  1. #1

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Right-CLick for Select

    hi guys! I have a listbox and i want the Item to be selected both when the user left or right-click on the that item..Is it posible? Thanks in advance!

  2. #2
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Right-CLick for Select

    you just need to handle the right button click and select the item in the listbox.
    c# Code:
    1. private void listBox1_MouseDown(object sender, MouseEventArgs e)
    2.         {
    3.             if (e.Button == MouseButtons.Right)
    4.             {
    5.                 int indexOver = listBox1.IndexFromPoint(e.X, e.Y);
    6.  
    7.                 if (indexOver >= 0 && indexOver < listBox1.Items.Count)
    8.                 {
    9.                     listBox1.SelectedIndex = indexOver;
    10.                     MessageBox.Show(listBox1.SelectedItem.ToString());
    11.                 }
    12.                 listBox1.Refresh();
    13.             }
    14.             if (e.Button == MouseButtons.Left)
    15.             {
    16.                 MessageBox.Show(listBox1.SelectedItem.ToString());
    17.             }
    18.         }
    Hope it helps you.
    Show Appreciation. Rate Posts.

  3. #3

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Re: Right-CLick for Select

    Thanks a lot Harsh..

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