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!
Printable View
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!
you just need to handle the right button click and select the item in the listbox.
Hope it helps you.c# Code:
private void listBox1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { int indexOver = listBox1.IndexFromPoint(e.X, e.Y); if (indexOver >= 0 && indexOver < listBox1.Items.Count) { listBox1.SelectedIndex = indexOver; MessageBox.Show(listBox1.SelectedItem.ToString()); } listBox1.Refresh(); } if (e.Button == MouseButtons.Left) { MessageBox.Show(listBox1.SelectedItem.ToString()); } }
Thanks a lot Harsh..