Right-click in listview

  • Thread starter Thread starter Guest
  • Start date Start date
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?
 
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.
 
Back
Top