C# 如何根据单元格值更改datagridview按钮文本?

C# 如何根据单元格值更改datagridview按钮文本?,c#,winforms,datagridview,C#,Winforms,Datagridview,我在Windows窗体上放置了一个DataGridView,DataGridView中有一个按钮。 现在我想根据单元格值更改按钮的文本 如何操作?将单元格强制转换为DataGridViewButtonCell,并根据需要使用它 var BtnCell = (DataGridViewButtonCell)YourDataGridView.Rows[yourindex].Cells[cellindex]; BtnCell.Value = "New Button Value"; 将单元格强制转换为D

我在Windows窗体上放置了一个DataGridView,DataGridView中有一个按钮。
现在我想根据单元格值更改按钮的文本


如何操作?

将单元格强制转换为DataGridViewButtonCell,并根据需要使用它

var BtnCell = (DataGridViewButtonCell)YourDataGridView.Rows[yourindex].Cells[cellindex];
BtnCell.Value = "New Button Value";

将单元格强制转换为DataGridViewButtonCell,并根据需要使用它

var BtnCell = (DataGridViewButtonCell)YourDataGridView.Rows[yourindex].Cells[cellindex];
BtnCell.Value = "New Button Value";
发件人:

您可以将true displays的属性值设置为单元格按钮上的文本属性值。

来自:


您可以将true显示的
UseColumnTextForButtonValue
属性值设置为单元格按钮上的文本属性值。

可能需要更多信息。尝试此操作可能需要更多信息。尝试此操作时出现错误:-无法将“System.Windows.Forms.DataGridViewTextBoxCell”类型的对象强制转换为类型“System.Windows.Forms.DataGridViewButtonCell”。您需要将单元格索引指向ButtonCell的正确索引。看起来您正在使用textboxcell的索引…..发生错误:-无法将“System.Windows.Forms.DataGridViewTextBoxCell”类型的对象强制转换为“System.Windows.Forms.DataGridViewButtonCell”。您需要将单元格索引指向ButtonCell的正确索引。看起来您正在使用textboxcell的索引。。。。。