为了账号安全,请及时绑定邮箱和手机立即绑定

如何处理Datagridview的“按钮”列中的单击事件?

如何处理Datagridview的“按钮”列中的单击事件?

HUH函数 2019-12-12 14:57:56
我正在使用C#开发Windows应用程序。我DataGridView用来显示数据。我在其中添加了一个按钮列。我想知道如何处理DataGridView中该按钮上的click事件。
查看完整描述

3 回答

?
收到一只叮咚

TA贡献1821条经验 获得超4个赞

对于WinForms,这里已完全回答:DataGridViewButtonColumn类


而在这里:如何:响应GridView控件中的按钮事件


取决于您实际使用的控件。(您的问题是说DataGrid,但是您正在开发Windows应用程序,因此要使用的控件中有一个DataGridView ...)


查看完整回答
反对 回复 2019-12-12
?
沧海一幻觉

TA贡献1824条经验 获得超5个赞

这是更好的答案:


您不能为DataGridViewButtonColumn中的按钮单元实现按钮单击事件。相反,您可以使用DataGridView的CellClicked事件并确定是否为DataGridViewButtonColumn中的某个单元触发了该事件。使用事件的DataGridViewCellEventArgs.RowIndex属性可以找到单击的行。


private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) {

  // Ignore clicks that are not in our 

  if (e.ColumnIndex == dataGridView1.Columns["MyButtonColumn"].Index && e.RowIndex >= 0) {

    Console.WriteLine("Button on row {0} clicked", e.RowIndex);

  }

}


查看完整回答
反对 回复 2019-12-12
  • 3 回答
  • 0 关注
  • 1541 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信