By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,112 Members | 1,642 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,112 IT Pros & Developers. It's quick & easy.

How can I tell a mouse right clicks over a listview item that's in

P: n/a
How can I tell a mouse right clicks over a listview item that's in a
container panel. I only want to display a popup menu if the user right click
the mouse over an item on the Listview. I don't not want to display this
menu if a node selected on the listview but user right click over the empty
space of the panel that contain the listview.

The problem here is when I use the Listview's Click Event, I don't have ways
to verify if the right mouse button is clicked, but with this event only
occurs if the user is clicking on one of the item of the Listview control.

If I use the ListView's MouseClick event, then I can't verify if the right
click occurs over a Listview item. Can someone tell me how to solve this
problem? Thanks.
--
Thanks.
Jul 27 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Try the MouseUp event instead. It has a MouseEventArgs as a parameter.
You can do a "if (e.Button == MouseButtons.Right)"...

"Pucca" <Pu***@discussions.microsoft.comwrote in message
news:F1**********************************@microsof t.com...
How can I tell a mouse right clicks over a listview item that's in a
container panel. I only want to display a popup menu if the user right
click
the mouse over an item on the Listview. I don't not want to display this
menu if a node selected on the listview but user right click over the
empty
space of the panel that contain the listview.

The problem here is when I use the Listview's Click Event, I don't have
ways
to verify if the right mouse button is clicked, but with this event only
occurs if the user is clicking on one of the item of the Listview control.

If I use the ListView's MouseClick event, then I can't verify if the right
click occurs over a Listview item. Can someone tell me how to solve this
problem? Thanks.
--
Thanks.

Jul 27 '06 #2

P: n/a
hopefully this wiil help you.,

/*------------------------------- code
--------------------------------*/
if ((e.Button == MouseButtons.Right) &&
(this.lvClients.SelectedItems.Count != 0))// &&
//(this.lvClients.SelectedItems[0].Focused == true))
{

CheckMenuItemEnable();
this.contextMenu.Show(this.lvClients,new Point(e.X,e.Y));
}
Sincerely,
simida

Pucca wrote:
How can I tell a mouse right clicks over a listview item that's in a
container panel. I only want to display a popup menu if the user right click
the mouse over an item on the Listview. I don't not want to display this
menu if a node selected on the listview but user right click over the empty
space of the panel that contain the listview.

The problem here is when I use the Listview's Click Event, I don't have ways
to verify if the right mouse button is clicked, but with this event only
occurs if the user is clicking on one of the item of the Listview control.

If I use the ListView's MouseClick event, then I can't verify if the right
click occurs over a Listview item. Can someone tell me how to solve this
problem? Thanks.
--
Thanks.
Jul 27 '06 #3

P: n/a
Thank you Brendan but I'm not able to tell if the mouse was click over an
item on the Listview control. The listview control is in the right panel of
a container. If the user clicks on the blank space in the panel but not on
any particualr item on the listview control then I don't want to popup the
contextmenustrip.
--
Thanks.
"Brendan Green" wrote:
Try the MouseUp event instead. It has a MouseEventArgs as a parameter.
You can do a "if (e.Button == MouseButtons.Right)"...

"Pucca" <Pu***@discussions.microsoft.comwrote in message
news:F1**********************************@microsof t.com...
How can I tell a mouse right clicks over a listview item that's in a
container panel. I only want to display a popup menu if the user right
click
the mouse over an item on the Listview. I don't not want to display this
menu if a node selected on the listview but user right click over the
empty
space of the panel that contain the listview.

The problem here is when I use the Listview's Click Event, I don't have
ways
to verify if the right mouse button is clicked, but with this event only
occurs if the user is clicking on one of the item of the Listview control.

If I use the ListView's MouseClick event, then I can't verify if the right
click occurs over a Listview item. Can someone tell me how to solve this
problem? Thanks.
--
Thanks.


Jul 27 '06 #4

P: n/a
I needed to do this a while ago, there may be a better way, but what I did
was this:

When the Right Mouse Button Is Pressed:

private void listBox1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
if(e.Button == MouseButtons.Right)
{
int itemPos = e.Y / listBox1.ItemHeight;
if (itemPos <= listBox1.Items.Count)
{
//Display your Context Menu.
// If you want the details of which item was clicked on its
available with listBox1.Items[itemPos].
}
}
}

Cheers,

Chris.

"Pucca" <Pu***@discussions.microsoft.comwrote in message
news:F1**********************************@microsof t.com...
How can I tell a mouse right clicks over a listview item that's in a
container panel. I only want to display a popup menu if the user right
click
the mouse over an item on the Listview. I don't not want to display this
menu if a node selected on the listview but user right click over the
empty
space of the panel that contain the listview.

The problem here is when I use the Listview's Click Event, I don't have
ways
to verify if the right mouse button is clicked, but with this event only
occurs if the user is clicking on one of the item of the Listview control.

If I use the ListView's MouseClick event, then I can't verify if the right
click occurs over a Listview item. Can someone tell me how to solve this
problem? Thanks.
--
Thanks.

Jul 27 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.