C#中dataGridView单击事件怎么写?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C#中dataGridView单击事件怎么写?相关的知识,希望对你有一定的参考价值。

this.dgvPcase.CellClick += new System.EventHandler(this.dgvPcase_CellClick);
上面这句提示:无法将类型"System.EventHandler"隐式转换为"System.Windows.Forms.DataGridViewCellEventHandler"
————————————————————我是分割线——————————————————
private void dgvPcase_CellClick(object sender, EventArgs e)

this.dgvPcase.CellClick+=System.Windows.Forms.DataGridViewCellEventHandler(this.dgvPcase_CelClick)追问

无法定义
System.Windows.Forms.DataGridViewCellEventHandler上下文无效

追答

添加了System.Windows.Forms的引用没?

或者直接在DataGridView的属性栏中,选择事件,双击生成事件方法

参考技术A CellClick(object sender, DataGridViewCellEventArgs e)
你dgvPcase_CellClick的事件错了
参考技术B MouseDown 这个事件
在里面写下面的代码
if(e.butten==Mouse.Right)

// 你想干什么?全加在这里

C# winform 如何用datagridview增、删、改数据

单击右击菜单“添加”,就可把在datagridview中添加的数据添加到数据库。同理实现单击“修改“、”删除“的功能。

参考技术A datagridview控件中的编辑、删除、更新事件里写相应的代码。当然首先得启用它的这些功能。

以上是关于C#中dataGridView单击事件怎么写?的主要内容,如果未能解决你的问题,请参考以下文章