2013-02-11 112 views
0

的按鈕如何設置正常和像我的DataGridViewButtonColumn 按鈕現在,我使用圖像按鈕,以便我能夠把圖像按鈕如何設置的壓圖片。設置在圖像上DataGridViewButtonColumn

其實我想點擊圖片的按鈕應該有圖片,點擊圖片後應該改變。請看下面的圖片。

之前enter image description here

enter image description here

回答

0

嘗試CellContentClick event這只是一個例子,我希望你能有所瞭解。

private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e) 
    { 
     if (e.ColumnIndex == 1) //Where your DataGridViewButtonColumn index 
     { 
      if (dataGridView2[e.ColumnIndex, e.RowIndex].EditedFormattedValue.ToString().Length > 0) 
      { 
       if (dataGridView2[e.ColumnIndex, e.RowIndex].EditedFormattedValue.ToString() == "Start") 
       { 
        dataGridView2[e.ColumnIndex, e.RowIndex].Value = "Stop"; 
       } 
       else 
       { 
        dataGridView2[e.ColumnIndex, e.RowIndex].Value = "Start"; 
       } 
      } 
      else 
       dataGridView2[e.ColumnIndex, e.RowIndex].Value = "Start"; 
     } 

    } 
+0

嗨spajce。我編輯了我的問題,請查看最後一列中的圖像是否有按鈕,以便我如何執行此操作。對不起,重播晚了。謝謝 – 2013-02-11 13:22:32

+0

我明白了,你有第三方'dataGridView'吧?我道歉,我不知道你正在使用的'dataGridView'。順便說一句,你從哪裏得到這個'dataGridView'? :) – spajce 2013-02-11 13:32:03

+0

嗨,不,它不是第三方datagridview我已經建立像這樣我現在沒有3個按鈕。我現在只有1個按鈕列,並且想要在按下按鈕和正常狀態時更改它的圖像(該圖像僅在Photoshop中創建)。 – 2013-02-11 13:37:36