Hi, I am making an application in C #.What I'm trying to achieve
- I select multiple rows with CTRL among the results in a DataGridView
- then I right click on it and shows the options
- i Click on the selected option
- Selected rows remain in the DataGridView, while other rows are deleted.
Problem when i'm stuck
- I select multiple lines using CTRL
- But when I find the right mouse button on the lines, the choice of several options
Note. I use the MouseClick event to right-click on rows and create a menu. The code for this event is shown below:
private void SearchPanelDataGridView_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
ContextMenuStrip smenu = new System.Windows.Forms.ContextMenuStrip();
var htest = SearchPanelDataGridView.HitTest(e.X, e.Y);
SearchPanelDataGridView.ClearSelection();
SearchPanelDataGridView.Rows[htest.RowIndex].Selected = true;
smenu.Items.Add("Clear Record").Name = "Clear Record";
smenu.Items.Add("Pay Amount").Name = "Pay Amount";
smenu.Items.Add("Break Apart").Name = "Break Apart";
smenu.Items.Add("View Details").Name = "View Details";
smenu.Items.Add("Choose Selected").Name = "Choose Selected";
smenu.Items.Add("Reset").Name = "Reset";
int CurrentMouseOverRow = SearchPanelDataGridView.HitTest(e.X, e.Y).RowIndex;
smenu.Show(SearchPanelDataGridView, new Point(e.X, e.Y));
smenu.ItemClicked += new ToolStripItemClickedEventHandler(smenu_ItemClicked);
}
}
source
share