1

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; }
}
Pikoh
  • 7,582
  • 28
  • 53
user7968633
  • 11
  • 1
  • 2
  • 1
    Can you set the Text property to Compare and UseColumnTextForButtonValue to True, – User6667769 May 05 '17 at 12:23
  • Using the code you posted, it's working fine for me. Do you have a minimal example to reproduce this (mis)behavior? – OhBeWise May 05 '17 at 14:08
  • I've set the UseColumnTextForButtonValue = Ture, but still not working...:( – user7968633 May 05 '17 at 14:09
  • @OhBeWise What!!! I still display nothing... My environment is VS2013 with .NET 4.5. The whole project [link](https://drive.google.com/file/d/0B6XUuzh41uenUUlEX0hTMkxBMXc/view) – user7968633 May 05 '17 at 14:15

1 Answers1

6

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

OhBeWise
  • 5,350
  • 3
  • 32
  • 60