您的位置:首页 > 其它

给datagridview添加右键菜单并确定其位置

2009-02-16 11:40 288 查看
1.添加一个menustrip到form.

添加相应的子菜单。

定义一全局Point 值,以便确定右键菜单的位置。

2.在datagridview的cell_mousedown事件中写代码:

private void QuerydataGV_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
if (this.QuerydataGV.Columns[e.ColumnIndex].Name.Equals("workbill"))
{
cmMenu.Show(this.QuerydataGV, newP);
// MessageBox.Show(this.QuerydataGV.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString());
}
}
}


3.在datagridview的mousedown事件中写代码:

private void dataGridView1_MouseDown(object sender, MouseEventArgs e)
{
newP = new Point(e.X, e.Y);
}


这样就搞定了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: