Right-click in listview

G

Guest

I've seen this technique for grabbing the listviewitem from a right-click:

private void listView1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
if(e.Button == MouseButtons.Right)
{
ListViewItem rClickedItem = listView1.GetItemAt(e.X, e.Y);
}
}

and this works fine if I right-click anywhere on the 1st column on any row.
But if I click on the data in any of the other columns I get a null
listviewitem, ie on the subitems. What am I doing wrong?
 
J

Jeff Gaines

I've seen this technique for grabbing the listviewitem from a right-click:

private void listView1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
if(e.Button == MouseButtons.Right)
{
ListViewItem rClickedItem = listView1.GetItemAt(e.X, e.Y);
}
}

and this works fine if I right-click anywhere on the 1st column on any row.
But if I click on the data in any of the other columns I get a null
listviewitem, ie on the subitems. What am I doing wrong?


The ListViewItem is in the first column, other columns contain sub-items.
Try replacing e.X with an integer between 0 and the width of the first
column.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top