【问题标题】:how can I display the item in the third column selected by the user from the dataGridView to the ComboBox如何将用户从 dataGridView 选择的第三列中的项目显示到 ComboBox
【发布时间】:2014-09-14 03:32:36
【问题描述】:

我在将用户选择的第三列(绑定源)从 dataGridView 显示到另一个表单中的组合框时出现问题,

我试过这段代码:

DataRowView drv = (DataRowView)immobilisation.immobilisationDataGridView1.CurrentRow.Cells[2].Value;
                    String valueOfItem = drv["intitulé_FI"].ToString();
                    comboBox5.Text = valueOfItem;

我得到这个错误: 无法将对象从“System.String”转换为“System.Data.DataRowView”。

如何将 DataGridView 中选择的项目显示到组合框,谢谢

【问题讨论】:

    标签: c# winforms datagridview combobox


    【解决方案1】:

    消息告诉您,您无法将特定单元格 (Cells[2].Value) 的值转换为 DataRowView。改用这个:

    comboBox5.Text = Convert.ToString(dataGridView1.CurrentRow.Cells[2].Value);
    

    如果这是您的列名,则将 2 替换为 "intitulé_FI"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-14
      • 2014-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-20
      相关资源
      最近更新 更多