Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Detecting mouse click location for a DataGridViewCell

$
0
0

I have a ContextMenuStrip in which different options are shown depending on which cell of a DataGridView the user clicks on. My problem is that I am unable to get the x & y co-ordinates of cells.

I get the mouse position by using :
Point mouse = MousePosition;

I tried getting the cell's location by saying:
Rectangle cell = dataGridView.Rows[r].Cells[idx].ContentBounds;
cell.Offset(this.Left + dataGridView.Left, this.Top + dataGridView.Top);

However, the cell co-ordinates I get are completely wrong. Any ideas?

Thanks for the help in advance guys!


Viewing all articles
Browse latest Browse all 2535

Trending Articles