2013-02-11 124 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