1

我有一个DataGridView类型的一列DataGridViewButtonColumn

我想在按钮上放一个文本。我尝试在“编辑列”选项中将文本放入“文本”属性中。我什至尝试过 swtteing UseColumnTextForButtonValue = true

我找不到让它工作的方法。

4

2 回答 2

5

是否要将 DataGridViewButtonColumn 文本绑定到 DataGridView 的数据源?如果是这样,则通过“编辑列”选项为该列设置 DataPropertyName。

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

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
    if (e.ColumnIndex == 0)
    {
        e.Value = "some value";
    }
}
于 2011-03-30T11:46:38.827 回答
0

假设您的 DataGridView 名称是 DataGridView1

 foreach (DataGridViewRow row in dataGridView1.Rows)
 {
     DataGridViewCell cell = row.Cells[0]; //Column Index for the dataGridViewButtonColumn
     cell.Value = "Your Text";
 }
于 2013-10-03T14:11:39.223 回答