Search code examples
c#winformsdatagridviewdatagridviewcolumndatagridviewbuttoncolumn

C# DataGridViewButtonCell set buttons text


I need to add my DataGridViewButtonCell to Column, and I need to name each other with different names.

But I didn't find any text properties.

Can anyone help me, please?

i do that stuff

DataGridViewButtonCell b = new DataGridViewButtonCell(); 
b.Value = "name"; 
MainTable.Rows.Add(b);

and it doesn't work


Solution

  • I admit that I don't understand why your method wouldn't work, but I was able to get the following to do what you wanted as a work-around:

            DataGridViewButtonCell b = new DataGridViewButtonCell();
            int rowIndex = MainTable.Rows.Add(b);
            MainTable.Rows[rowIndex].Cells[0].Value = "name";
    

    In my example I'm assuming you only have one column (a DataGridViewButtonColumn). You should be able to modify this however you like so long as you set the value after you add the row. Again, not sure why that's the case...