Search code examples
c#winformsdatagridviewdatagridviewbuttoncolumn

DataGridView row button text not appearing


I have a DataGridView control which looks like the following at design time:

enter image description here

Properties:

enter image description here

Then, at run-time, that DataGridView is populated as follows:

foreach (Word c in items)
{
    dataGridView1.Rows.Add((i+1).ToString(), c.GroupNo, c.Name, c.CorrectnessCount);

    ... ... ...
    ... ... ...
    ... ... ...
 }

And, each row-button's click event is handled as follows:

 private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
        var senderGrid = (DataGridView)sender;

        if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn &&
            e.RowIndex >= 0)
        {
            //TODO - Button Clicked - Execute Code Here
            btnEdit_Click(sender, e);
        }
    }

Here is the output:

enter image description here

Now, can you spot the issue in the output?

Thre should be Play written in the foreground of each button. The buttons have no text in their caption area.

How can I solve this issue?


Solution

  • set UseColumnTextForButtonValue of DataGridViewButtonColumn to true. designer screen shows that it is false