您的位置:首页 > 其它

datagridview右键菜单鼠标当前所在数据行进行选中,并在无数据时不显示右键菜单。

2011-10-27 15:28 1346 查看
View Code

1 private void DgvConsignmentBills_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
2 {
3 if (e.Button == MouseButtons.Right)
4 {
5 if (e.RowIndex >= 0)
6 {
7 this.DgvConsignmentBills.ClearSelection();
8 this.DgvConsignmentBills.Rows[e.RowIndex].Selected = true;
9 this.DgvConsignmentBills.CurrentCell = this.DgvConsignmentBills.Rows[e.RowIndex].Cells[e.ColumnIndex];
10 contextMenuStrip1.Show(MousePosition.X, MousePosition.Y);
11 }
12 }
注意:使用次代码需要江datagridview的关联右键菜单去掉。不要在设计器中进行设计。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐