每行更改DataGridViewButtonColumn的按钮文本

我有一个DataGridView ,其中一列是DataGridViewButtonColumn类型。

我想在按钮上放一个文字。 我已经尝试在“编辑列”选项中将文本放在“文本”属性中。 我甚至尝试过使用UseColumnTextForButtonValue = true

我找不到办法让它发挥作用。

您是否要将DataGridViewButtonColumn Text绑定到DataGridView的DataSource? 如果是,则通过“编辑列”选项为列设置DataPropertyName。

否则,您可以尝试使用DataGridView的CellFormatting事件:

 private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { if (e.ColumnIndex == 0) { e.Value = "some value"; } } 

假设您的DataGridView名称是DataGridView1

  foreach (DataGridViewRow row in dataGridView1.Rows) { DataGridViewCell cell = row.Cells[0]; //Column Index for the dataGridViewButtonColumn cell.Value = "Your Text"; }