Can't show the text in DataGridViewButtonColumn

3.2k Views Asked by At

I've try to practice with "DataGridViewButtonColumn" property.

But here is a strange problem that I can't display the text in button in first column.

ScreenShot:

I try it in different methods, but it still not working.

Here is my code snippet.

Thanks ^__^

private void Form1_Load(object sender, EventArgs e)
    {
        Demo d;
        List<Demo> list = new List<Demo>();

        for (int i = 0; i < 10; i++)
        {
            d = new Demo();

            d.No = i.ToString();
            d.Name = "A" + i;
            list.Add(d);
        }

        foreach (Demo item in list)
            dataGridView1.Rows.Add(item.No, item.Name);
    }

public struct Demo
{
    public string No { get; set; }
    public string Name { get; set; }
}
1

There are 1 best solutions below

0
OhBeWise On

Read up on DataGridViewButtonColumn.UseColumnTextForButtonValue.

Set the value to false to get your desired results:

this.Column1.UseColumnTextForButtonValue = false;

Setting it to true means that it will use DataGridViewButtonColumn.Text for every button's text value (which you didn't set - and therefore shows blank text on all buttons). For example:

this.Column1.UseColumnTextForButtonValue = true;
this.Column1.Text = "Click Here";

10 "Click Here" buttons