DataGridView中实现右击选中当前行功能,并通过ContextMenuStrip获取当前行
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); }
版权声明:本文为MarsPanda原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。