2012-09-18
添加cell mouse down事件.
private void gvShow_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e) { if (e.Button == MouseButtons.Right) { gvShow.ClearSelection(); gvShow.Rows[e.RowIndex].Cells[e.ColumnIndex].Selected = true; gvShow.CurrentCell = gvShow.Rows[e.RowIndex].Cells[e.ColumnIndex]; } }
测试效果,正确的alert行号
private void TestToolStripMenuItem_Click(object sender, EventArgs e) { string str = gvShow.CurrentCell.RowIndex.ToString(); MessageBox.Show(str); }