Ira*_*ili 1 c# combobox winforms
我正在使用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;
}
Run Code Online (Sandbox Code Playgroud)
对不起,我的英语不好.
好像你想要一个独特dataSource的ComboBox 列表.如果您使用的是.NET 3及更高版本,则可以使用:
List<T> withDupes = SellerNameList;
List<T> noDupes = withDupes.Distinct().ToList();
comboBox1.DataSource = noDupes;
Run Code Online (Sandbox Code Playgroud)