Reputation: 1869
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
Upvotes: 19
Views: 71037
Reputation: 1
[Colimn.Name].Text = "Click Me"
[Colimn.Name].UseColumnTextForButtonValue = True
button_Text Use this code in Form_Load event-it will name all buttons in that column as "Click Me".
Upvotes: -1
Reputation: 3322
If you want to set the same text for all buttons, you can:
GridView
properties click on edit columnsText
to the text you want to see on each buttonUserColumnTextForButtonValue
to True
See below:
Upvotes: 22
Reputation: 1749
I know you got your answer accepted but I added these in constructor
and it worked for me. The only thing I was missing is UseColumnTextForButtonValue = true
public Form1()
{
InitializeComponent();
var editColumn = new DataGridViewButtonColumn
{
Text = "Edit",
UseColumnTextForButtonValue = true,
Name = "Edit",
DataPropertyName = "Edit"
};
dataGridView1.Columns.Add(editColumn);
}
Upvotes: 7
Reputation: 81
Use this to show the same text on all buttons with default button at first
DataGridView.Columns["Buttons_Index"].DefaultCellStyle.NullValue = "name";
Upvotes: 5
Reputation: 3065
If you have just one column and that's a buttoncolumn by default
MainTable.Rows.Add("Some text");
will suffice.
Upvotes: 0
Reputation: 426
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...
Upvotes: 7
Reputation: 1831
Try example given in below link. http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewbuttoncolumn.usecolumntextforbuttonvalue.aspx.
Upvotes: 1
Reputation: 73502
If you want all the buttons to have same text use UseColumnTextForButtonValue property.
If you want different text for each button then use DataGridViewCell.Value property
Upvotes: 51