【问题标题】:Load column data into comboBox将列数据加载到组合框中
【发布时间】:2023-03-30 10:25:01
【问题描述】:

我有一个Datagridview,其中包含一些来自 excel 文件的数据。我有一个ComboBox,它必须显示来自Datagridview 的特定列数据。我怎样才能做到这一点?谢谢。

我试过这个没有结果:

private void comboBox5_SelectedIndexChanged(object sender, EventArgs e)
{
    comboBox5.Items.Clear();
    foreach (DataGridViewRow row in dataGridViewNE.Rows)
    {
        comboBox5.Items.Add(row.Cells[1].Value.ToString());
    }

【问题讨论】:

  • 为什么要清除选择更改时的所有项目?你在使用 WinForms 吗?
  • 如果用户更新datagridview,我认为它必须清除旧值。我错了?我正在使用 WinForms。
  • 您能否提供更多有关您面临的问题的信息?
  • 我只需要使用 Datagridview 中的特定列填充 ComboBox。
  • 我很抱歉。我仍然对代码感到困惑。您要在什么操作上填充组合框。?在更改组合框选择时应该发生什么?如我所见,您正在清除每次选择更改的集合并填充相同的数据。我想,在加载表单或视图期间,您应该填充项目,并且在选择更改时,您应该执行预期的操作

标签: c# datagridview combobox


【解决方案1】:

好的。我已经解决了:

private void ComboBox5_MouseClick(object sender, MouseEventArgs e)
{
    foreach (DataGridViewRow row in dataGridViewNE.Rows)
    {
        comboBox5.Items.Add(row.Cells[0].Value.ToString());
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-04
    • 2012-10-08
    • 1970-01-01
    • 2014-12-06
    • 1970-01-01
    • 2020-03-13
    • 1970-01-01
    相关资源
    最近更新 更多