Hi,
I am trying to get an item from a ListView from the right clicked
location. I have a ContextMenuStrip associated with the ListView. The
code looks like:
private void Delete_Clicked(object sender,
ToolStripItemClickedEventArgs e)
{
Rectangle p = e.ClickedItem.Bounds;
Point t = this.PointToScreen(p.Location);
ListViewItem c = DisplayFieldListView.GetItemAt(t.X,
t.Y);
if(c != null)
DisplayFieldListView.Items.Remove(c);
}
The item c is not found and is remaining null. Am I missing
something?
Thanks,
Avanti
ClayB - 22 Feb 2007 08:58 GMT
I suspect coordinate system discrepencies are making this code fail.
With this code,
Point t = ...
ListViewItem c = DisplayFieldListView.GetItemAt(t.X,t.Y);
the point t should be in the coordinate system of
DisplayFieldListView. But in your code, you are using
this.PointToScreen(p.Location) to define t. Does 'this' refer to
DisplayFieldListView? If not, then that would prevent things from
working.
Another problem would be if p.Location is in not in the 'this'
coordinate system since you are calling this.PointToScreen to move it
to screen coordinates.
==============
Clay Burch
Syncfusion, Inc.