DataGridView右键选中某单元格(C# Winfrom)

  1. //添加下面事件 
  2. private void DataGridView_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
  3.         {
  4.             if (e.RowIndex >= 0)
  5.             {
  6.                 if (e.Button == System.Windows.Forms.MouseButtons.Right)
  7.                 {
  8.                    dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Selected = true;
  9.                     dataGridView1.ClearSelection();
  10.                 }
  11.             }
  12.         

你可能感兴趣的:(C#)