嗨,我正在C#中創建一個應用程序。在鼠標單擊時保持多重選擇並執行其他功能
我想實現
- 我的DataGridView
- 然後選擇多行與CTRL結果中我右鍵點擊它,它顯示選項
- 我點擊到選擇選項
- 該只選擇行停留在的DataGridView和其他行被刪除
問題在哪裏卡住了
- 我選擇多行與CTRL
- 但是,當我右鍵點擊在多行選擇消失
注意:我正在使用MouseClick事件來右鍵單擊行並生成一個菜單。此事件的代碼如下:
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"; // Choose Rows Option
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);
}
}
讓我知道如果你有任何問題的答案:) –