I explain what I need: I want that, when I right click on a cell , DataGridView
a menu is displayed on it (on the cell).
The problem is: That when I right click the menu is always displayed at the top of the menu DataGridView
and NOT in the clicked cell.
I right-clicked where the red dot is but the menu still appears at the top of the DataGridView
, and so on anywhere I right-clicked.
Time to show code: The following code is the function I have so far.
private void lista_dias_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
ContextMenuStrip menu = new ContextMenuStrip();
int posiscion = lista_dias.HitTest(e.X, e.Y).RowIndex;
// if (posiscion >= 0) {
menu.Items.Add("agregar").Name = "AGREGAR";
menu.Items.Add("eliminar").Name = "Eliminar";
menu.Items.Add("detalles").Name = "DETALLES";
//}
menu.Show(lista_dias, new Point(e.X, e.Y));
}
}
Said event was created automatically from the interfaces that C# has, the event is CellMouseClick
.
In advance thanks for the help.
It occurs to me that you can do this by getting the coordinate of each cell.
Assuming your
DataGridView
name is : day_list :The result obtained is the following:
I hope it helps you... Greetings!
take this structure, it works very well for me.
I explain: Inside the grid, you right click on your record, then a tab is displayed, where it gives you an option, in my case, "Delete Product", immediately, the selected record is deleted and in turn it is deleted from the database.
For info about the technology I apply: Entity Framework, C# and SQL server.
I hope in one way or another I have helped to solve your problem or at least an idea.