我有一个DataGridView
类型的一列DataGridViewButtonColumn
。
我想在按钮上放一个文本。我尝试在“编辑列”选项中将文本放入“文本”属性中。我什至尝试过 swtteing UseColumnTextForButtonValue = true
。
我找不到让它工作的方法。
我有一个DataGridView
类型的一列DataGridViewButtonColumn
。
我想在按钮上放一个文本。我尝试在“编辑列”选项中将文本放入“文本”属性中。我什至尝试过 swtteing UseColumnTextForButtonValue = true
。
我找不到让它工作的方法。
是否要将 DataGridViewButtonColumn 文本绑定到 DataGridView 的数据源?如果是这样,则通过“编辑列”选项为该列设置 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";
}