【问题标题】:How to change datagridview button text on cell value basis?如何根据单元格值更改 datagridview 按钮文本?
【发布时间】:2015-04-24 07:25:42
【问题描述】:

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

我该怎么做?

【问题讨论】:

标签: c# winforms datagridview


【解决方案1】:

将 Cell 转换为 DataGridViewButtonCell 并根据需要使用它..

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

【讨论】:

  • 发生错误:-无法将“System.Windows.Forms.DataGridViewTextBoxCell”类型的对象转换为“System.Windows.Forms.DataGridViewButtonCell”类型。
  • 您需要将单元格索引指向 ButtonCell 的正确索引。看起来您使用的是 textboxcell 的索引.....
【解决方案2】:

来自MSDN

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-05
    • 1970-01-01
    • 2021-08-18
    • 1970-01-01
    • 2023-04-06
    • 1970-01-01
    相关资源
    最近更新 更多