【问题标题】:How to change the value of specific column in DataGridView based on selected index changed of DataGridViewComboxColum?如何根据 DataGridViewComboxColum 的选定索引更改 DataGridView 中特定列的值?
【发布时间】:2019-07-19 21:39:29
【问题描述】:

我的 Windows 窗体应用程序中有一个名为“cbxActionType”的 DataGridViewComboxColum,它的项目集合中有以下值。 • 供参考 • 供评论 • 供审查……等。 DataGridView1 有一个名为“NDays”的列,用于存储天数。如果“cbxActionType”选择值更改为“For Information”,如何将 NDays 列值设置为 0(零天)?

DataGridview Combobox Column

【问题讨论】:

  • 一种可能的方法是连接网格CellValueChanged 事件。在这种情况下,检查更改的单元格是否在“操作类型”列中,如果更改的值在该列中,则在该行上相应地设置“天”值。
  • 谢谢@JohnG,我在 CellValueChanged 事件中有以下代码来解决这个问题,但它没有进入 if 条件块。

标签: datagridview selectedindexchanged datagridviewcombobox


【解决方案1】:
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
    if (dataGridView1.CurrentRow.Cells["cbxActionType"].Value == "For Information")
    {
        dataGridView1.CurrentRow.Cells["NDays"].Value = 0;               
    }
}

【讨论】:

  • ToString()添加到“if”中的Value中......就像...... if (dataGridView1.CurrentRow.Cells["cbxActionType"].Value.ToString() == "For Information")
  • @JohnG 感谢您为我指出正确的解决方案。感谢您的努力。
猜你喜欢
  • 1970-01-01
  • 2019-10-06
  • 2023-04-03
  • 2022-08-09
  • 1970-01-01
  • 2023-02-02
  • 2013-03-01
  • 2020-07-19
  • 1970-01-01
相关资源
最近更新 更多