473,473 Members | 1,847 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

right click in c#

Hi All,

I have a data grid and I created a context menu for the data grid and
is working fine. The context menu is sensitive to the current selected
row.
I would like to know., when a user RIGHT click on a particular row, I
want to select the row and then show the context menu (like outlook).
Could someone give me some pointers on this. I did some experiments but
none worked so far.

Thanks.

Dec 22 '06 #1
2 24906
This works for me...

private void MyDataGridView_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Right) return;
DataGridView.HitTestInfo Hti = MyDataGridView.HitTest(e.X, e.Y);
if (Hti.Type == DataGridViewHitTestType.Cell)
{
if (MyDataGridView.Rows.Count 0)
{
MyDataGridView.CurrentCell = MyDataGridView[Hti.ColumnIndex,
Hti.RowIndex];

ShowContextMenu(this.PointToScreen(MyDataGridView. PointToClient(e.Location))
);
}//EndIf
}//EndIf
}//EndEvh MyDataGridView_MouseUp
Hope this helps,

Steph.


"DBC User" <db*****@gmail.comwrote in message
news:11**********************@48g2000cwx.googlegro ups.com...
Hi All,

I have a data grid and I created a context menu for the data grid and
is working fine. The context menu is sensitive to the current selected
row.
I would like to know., when a user RIGHT click on a particular row, I
want to select the row and then show the context menu (like outlook).
Could someone give me some pointers on this. I did some experiments but
none worked so far.

Thanks.

Dec 22 '06 #2

TheSteph wrote:
This works for me...

private void MyDataGridView_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Right) return;
DataGridView.HitTestInfo Hti = MyDataGridView.HitTest(e.X, e.Y);
if (Hti.Type == DataGridViewHitTestType.Cell)
{
if (MyDataGridView.Rows.Count 0)
{
MyDataGridView.CurrentCell = MyDataGridView[Hti.ColumnIndex,
Hti.RowIndex];

ShowContextMenu(this.PointToScreen(MyDataGridView. PointToClient(e.Location))
);
}//EndIf
}//EndIf
}//EndEvh MyDataGridView_MouseUp
Hope this helps,

Steph.


"DBC User" <db*****@gmail.comwrote in message
news:11**********************@48g2000cwx.googlegro ups.com...
Hi All,

I have a data grid and I created a context menu for the data grid and
is working fine. The context menu is sensitive to the current selected
row.
I would like to know., when a user RIGHT click on a particular row, I
want to select the row and then show the context menu (like outlook).
Could someone give me some pointers on this. I did some experiments but
none worked so far.

Thanks.
Thanks and it worked. Thats what I was looking for.

Dec 26 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: The Roys | last post by:
I want to be able to detect if an image has been right-clicked. I have 5 images in my program. If I Click the image it gets selected by my program. But I want to be able to Right-Click one of the...
8
by: George Hester | last post by:
In a page I have when the user left-clicks the page a Input box for a form gets the focus. But if the user right-clicks the page the Input box is not getting the focus. I'd like the Input box to...
4
by: John Bailo | last post by:
Is there any way to enable right click on a winform button?
2
by: Sean | last post by:
Hi, I have a treeview and user can right click the treenodes, depending on the nodes, different shortcut menu will appear. I want only the shortcut menu to appear if the point of the right...
2
by: Dino M. Buljubasic | last post by:
I have a list view with couple of items in it. When I left click on an item, a form opens displaying that item's properties. So that works fine. However, accidentally I found out that when I...
7
by: Robert | last post by:
Can I programmatically disable the right click context menu?
11
by: Terry Olsen | last post by:
How can I catch a right-click on a DropDownMenuItem?
0
by: Ben | last post by:
I have a DataGrid in where I have code in the MouseUp Event that checks the area of the Grid clicked, and highlights the entire row. Problem is, that if you the "Right-Click" on another row, it...
4
by: Pucca | last post by:
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...
1
dfound
by: dfound | last post by:
I created an encrypting software and decided to add a shell extension.(if thats the correct word).. what i did was to add values to registry so that an option will show up when a file/folder is...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.