亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何處理Datagridview的“按鈕”列中的單擊事件?

如何處理Datagridview的“按鈕”列中的單擊事件?

HUH函數 2019-12-12 14:57:56
我正在使用C#開發Windows應用程序。我DataGridView用來顯示數據。我在其中添加了一個按鈕列。我想知道如何處理DataGridView中該按鈕上的click事件。
查看完整描述

3 回答

?
收到一只叮咚

TA貢獻1821條經驗 獲得超5個贊

對于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 關注
  • 1656 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號