Solved

How to select a cell in a DataGridView as well as show context menu when right click

Posted on 2006-07-08
1
313 Views
Last Modified: 2010-04-16
I have added a context menu to my DataGridView which appears when right-clicking on a cell. But how do I also select that cell as well as pop up the menu when it is right-clicked? I've tried using the MouseClick and Click events but they don't seem to be called when a context menu is present.
0
Comment
Question by:groovyjon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 96

Accepted Solution

by:
Bob Learned earned 125 total points
ID: 17065152
Add a CellMouseDown handler like this:

  private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
  {
     if (e.Button == MouseButtons.Right)
    {
       // Set the current cell to the one right-clicked on.
       DataGridView.HitTestInfo hit = this.dataGridView1.HitTest(e.X, e.Y);
       this.dataGridView1.CurrentCell = this.dataGridView1[e.ColumnIndex, e.RowIndex];
     }
  }

Bob
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question