1

I have a DataGridView with one column of type DataGridViewButtonColumn.

I want to put a text on the button. I've tried in the Edit Column options to put the text in the Text properties. I have even tried swtteing UseColumnTextForButtonValue = true.

I can't find a way to make it work.

eglease
  • 2,445
  • 11
  • 18
  • 28
hadi
  • 137
  • 2
  • 4
  • 8

2 Answers2

5

Did you want to bind DataGridViewButtonColumn Text to the DataGridView's DataSource? If so then set the DataPropertyName for the column via the Edit Column options.

Otherwise you can try using the DataGridView's CellFormatting event:

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
    if (e.ColumnIndex == 0)
    {
        e.Value = "some value";
    }
}
Adrian Toman
  • 11,316
  • 5
  • 48
  • 62
  • This should have been accepted. Note: `e.Value` is just what is __displayed__ and has nothing to do with the `cell.Value`, which still can be whatever we need, including a __real__ `Button`: ` Button btn = DGV[2, e.RowIndex].Value as Button; if (btn != null) e.Value = btn.Text;` – TaW Aug 02 '14 at 11:40
0

Assuming that your DataGridView name is DataGridView1

 foreach (DataGridViewRow row in dataGridView1.Rows)
 {
     DataGridViewCell cell = row.Cells[0]; //Column Index for the dataGridViewButtonColumn
     cell.Value = "Your Text";
 }
Ankur Sharma
  • 283
  • 2
  • 13