?
Solved

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

Posted on 2006-07-08
1
Medium Priority
?
316 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 500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

752 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