471,076 Members | 1,202 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,076 software developers and data experts.

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

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
4 10045
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
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
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
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.

Similar topics

5 posts views Thread by John Champaign | last post: by
3 posts views Thread by mitsura | last post: by
3 posts views Thread by TM | last post: by
1 post views Thread by .NetHelpWanted | last post: by
3 posts views Thread by Steve Long | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.