您的位置:首页 > 其它

DataGridView中实现右击选中当前行功能,并通过ContextMenuStrip获取当前行

2012-09-18 16:00 519 查看
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);
}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐