在datagridview的按钮单击事件 [英] button click event in datagridview

查看:669
本文介绍了在datagridview的按钮单击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在datagridview.When纽扣电池的按钮时,另一个datagridview的应该是。对于在按钮栏每个按钮的点击可见,在新的datagridview的数据应该是differed.I不知道如何实现按钮单击事件而有所不同,每row.Please帮助我的样本code。

I am having a button cell in datagridview.When that button is clicked,another datagridview should be visible .For every button click in the button column,the data in new datagridview should be differed.I dont know how to implement the button click event which differs for every row.Please help me with the sample code.

推荐答案

您无法实现在 DataGridViewButtonColumn 扣式电池的一个按钮点击事件。相反,您使用的DataGridView的 CellClicked 事件,并确定是否触发的事件在细胞中的 DataGridViewButtonColumn 。使用事件的 DataGridViewCellEventArgs.RowIndex 属性来找出被点击哪一行。

You can't implement a button clicked event for button cells in a DataGridViewButtonColumn. Instead, you use the DataGridView's CellClicked event and determine if the event fired for a cell in your DataGridViewButtonColumn. Use the event's DataGridViewCellEventArgs.RowIndex property to find out which row was clicked.

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);
    }
}

在MSDN文档<一个href=\"http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewbuttoncolumn.aspx\">DataGridViewButtonColumn类有一个更完整的例子。

这篇关于在datagridview的按钮单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆