Right Click Selection

  • Thread starter Thread starter rajkiranpro
  • Start date Start date
R

rajkiranpro

I want to select an item in a list view whenever the right mouse button is
clicked..

I just see a click event.

I tried to get the coordinates form the mousedown event but how to use the
coordinates to select an item from the listbox

if (e.Button == MouseButtons.Right)
{
//dono what to do next
}

Any Suggestions?


Thanks
Rajkiran
 
rajkiranpro said:
I want to select an item in a list view whenever the right mouse button is
clicked..

I just see a click event.

I tried to get the coordinates form the mousedown event but how to use
the coordinates to select an item from the listbox

if (e.Button == MouseButtons.Right)
{
//dono what to do next
}

Any Suggestions?

First you said "list view" and then you said "listbox." Which one is it?
 
rajkiranpro said:
I want to select an item in a list view whenever the right mouse button is
clicked..

Your list view version of your question might go something like this
The listview has three columns
There are three textboxes on the form

using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace Test2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
string[] data = { "ene", "mene", "mo" };
ListViewItem list = new ListViewItem(data);
listView1.Items.Add(list);
this.listView1.MouseUp += new
MouseEventHandler(listView1_MouseUp);
}

private void listView1_MouseUp(object ender, MouseEventArgs e)
{
ListView.SelectedListViewItemCollection contents =
this.listView1.SelectedItems;
if (contents.Count > 0 && e.Button == MouseButtons.Right)
{
textBox1.Text = contents[0].SubItems[0].Text;
textBox2.Text = contents[0].SubItems[1].Text;
textBox3.Text = contents[0].SubItems[2].Text;
}
else
textBox1.Text = "error";
}
}
}
 
Back
Top