Groups | Blog | Home
all groups > dotnet windows forms > may 2007 >

dotnet windows forms : Right-click in listview


Tim Johnson
5/6/2007 11:01:01 PM
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?

Jeff Gaines
5/7/2007 2:33:13 AM
On 07/05/2007 in message
[quoted text, click to view]


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.

--
Tim Johnson
5/7/2007 7:14:00 AM
That did it, thanks.
AddThis Social Bookmark Button