datagridview中的按钮单击事件 [英] button click event in datagridview
问题描述
您不能实现按钮单击事件对于 DataGridViewButtonColumn
中的按钮单元格。而是使用DataGridView的 CellClicked
事件,并确定您的 DataGridViewButtonColumn
中的单元格是否触发了该事件。使用事件的 DataGridViewCellEventArgs.RowIndex
属性来找出被点击的行。
private void dataGridView1_CellClick(object sender,DataGridViewCellEventArgs e){
//忽略不在我们
中的点击if(e.ColumnIndex == dataGridView1.Columns [MyButtonColumn]。Index&& amp ; e.RowIndex> = 0){
Console.WriteLine(Button on row {0} clicked,e.RowIndex);
}
}
DataGridViewButtonColumn类有一个更完整的例子。
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.
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);
}
}
The MSDN documentation on the DataGridViewButtonColumn class has a more complete example.
这篇关于datagridview中的按钮单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!