dataGridView右键菜单并选中该行

 程序代码:
  1. private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
  2.         {
  3.             if (e.Button == MouseButtons.Right)
  4.             {
  5.                 if (e.RowIndex >= 0)
  6.                 {
  7.                     dataGridView1.ClearSelection();
  8.                     dataGridView1.Rows[e.RowIndex].Selected = true;
  9.                     dataGridView1.CurrentCell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
  10.                     contextMenuStrip1.Show(MousePosition.X, MousePosition.Y);
  11.                 }
  12.             }
  13.         }

posted on 2008-12-24 12:52  恒波  阅读(203)  评论(0)    收藏  举报

导航