PC Review


Reply
Thread Tools Rate Thread

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

 
 
=?Utf-8?B?UHVjY2E=?=
Guest
Posts: n/a
 
      27th Jul 2006
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.
 
Reply With Quote
 
 
 
 
Brendan Green
Guest
Posts: n/a
 
      27th Jul 2006
Try the MouseUp event instead. It has a MouseEventArgs as a parameter.
You can do a "if (e.Button == MouseButtons.Right)"...

"Pucca" <(E-Mail Removed)> wrote in message
news:F1987470-86D0-4AC7-A38B-(E-Mail Removed)...
> 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.



 
Reply With Quote
 
simida
Guest
Posts: n/a
 
      27th Jul 2006
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.


 
Reply With Quote
 
=?Utf-8?B?UHVjY2E=?=
Guest
Posts: n/a
 
      27th Jul 2006
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" <(E-Mail Removed)> wrote in message
> news:F1987470-86D0-4AC7-A38B-(E-Mail Removed)...
> > 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.

>
>
>

 
Reply With Quote
 
ChrisM
Guest
Posts: n/a
 
      27th Jul 2006
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" <(E-Mail Removed)> wrote in message
news:F1987470-86D0-4AC7-A38B-(E-Mail Removed)...
> 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.



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ListView: how to detect if the item is selected with the first mouse click? Jack Windows XP General 1 20th Jul 2008 06:43 PM
Checking a listview item while mouse click Manikandan Microsoft C# .NET 7 3rd Jul 2007 12:29 PM
Change Item in listview on mouse over Steve Long Microsoft VB .NET 3 18th Nov 2005 01:48 AM
How to detect which ListView item user clicks? Robert Microsoft Dot NET Compact Framework 10 27th Apr 2005 12:36 AM
bug with listview in C# - 2 clicks required to select item Bruce Bakely Microsoft Dot NET Compact Framework 4 26th Aug 2003 05:40 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:10 AM.