我正在用ComboBox单元格的值填充DataGridView。现在,我不想重复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;
}对不起我的英语不好。
发布于 2010-11-21 16:50:27
似乎您希望为您的dataSource为ComboBox提供一个唯一的列表。如果您使用的是.NET 3及以上版本,您可以使用:
List<T> withDupes = SellerNameList;
List<T> noDupes = withDupes.Distinct().ToList();
comboBox1.DataSource = noDupes;发布于 2010-11-21 16:41:53
最简单的方法是通过一个集合和LINQ,我会说。
试试看这个链接的介绍。
https://stackoverflow.com/questions/4238939
复制相似问题