DataGridViewCell Feauture



I would need to show a userpopup when I right-click on a cell of a datagridview. The popup must appear under the cell.
is there any way to do this?
Currently I am using a context menu to allow the choice of various options.
I would like to use a userpopup as it is necessary to display a long list of values.
Thank you?

  • You must to post comments

Cells are not widgets and don’t have a location or size, they are rendered in the browser by building the HTML using the various cell renderers.

You can use Control.MousePosition.X for the X position, it’s already relative to the screen.

You can calculate the top or bottom of the cell in CellMouseDown like this:

for (int i = this.dataGridView.FirstDisplayedRowIndex; i <= e.RowIndex; i++)
  bottom+= this.dataGridView.Rows[i].Height;

Add the header height.

        bottom += this.DataGridView.ColumnHeadersHeight;

Convert to screen.

       var loc = this.DataGridView.PointToScreen(new Point(0, bottom));

Show the popup.

       popup.ShowPopup(Control.MousePosition.X, bottom);

To align the left position is more complicated since the columns may scroll partially.


  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.