1

I have a DataGridView placed on a Windows Form and a Button inside the datagridview.
Now I want to change the text of a button on cell value basis.

How can i do it?

Mackan
  • 6,200
  • 2
  • 25
  • 45
Sahil Magoo
  • 95
  • 2
  • 2
  • 12

2 Answers2

3

cast the Cell as a DataGridViewButtonCell and use it as you wish..

var BtnCell = (DataGridViewButtonCell)YourDataGridView.Rows[yourindex].Cells[cellindex];
BtnCell.Value = "New Button Value";
Spencer Waz
  • 155
  • 8
  • ERROR Occured :-Unable to cast object of type 'System.Windows.Forms.DataGridViewTextBoxCell' to type 'System.Windows.Forms.DataGridViewButtonCell'. – Sahil Magoo Apr 24 '15 at 07:49
  • You need to point your cell index to the correct index of your ButtonCell. It looks like your using the index of a textboxcell..... – Spencer Waz Apr 24 '15 at 08:05
1

From MSDN:

You can set UseColumnTextForButtonValue property value of true displays to the Text property value on the cells button.

Frits
  • 7,341
  • 10
  • 42
  • 60
ngochoaitn
  • 27
  • 4