3 回答

TA貢獻1821條經驗 獲得超5個贊
對于WinForms,這里已完全回答:DataGridViewButtonColumn類
而在這里:如何:響應GridView控件中的按鈕事件
取決于您實際使用的控件。(您的問題是說DataGrid,但是您正在開發Windows應用程序,因此要使用的控件中有一個DataGridView ...)

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);
}
}
- 3 回答
- 0 關注
- 1656 瀏覽
添加回答
舉報