gpt4 book ai didi

c# - DataGridView 和 ComboBox 问题

转载 作者:太空宇宙 更新时间:2023-11-03 18:46:14 27 4
gpt4 key购买 nike

我正在用 DataGridView 单元格的值填充 ComboBox。现在,我不想重复 ComboBox 中已有的值。

因此,例如:

  • 比尔·盖茨
  • 史蒂夫·乔布斯
  • 史蒂夫鲍尔默
  • 接替乔布斯

我想删除出现不止一次的所有值。

这是我的代码:

private void btnFilter_Click(object sender, EventArgs e)
{
ArrayList SellerNameList = new ArrayList();

for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
SellerNameList.Add(dataGridView1.Rows[i].Cells["cSellerName"].Value);
}
comboBox1.DataSource = SellerNameList;
}

抱歉我的英语不好。

最佳答案

您似乎想要一个用于 ComboBox 的 dataSource 的唯一列表。如果您使用的是 .NET 3 及更高版本,您可以使用:

List<T> withDupes = SellerNameList;
List<T> noDupes = withDupes.Distinct().ToList();

comboBox1.DataSource = noDupes;

关于c# - DataGridView 和 ComboBox 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4238939/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com